467 lines
18 KiB
Objective-C
467 lines
18 KiB
Objective-C
//
|
|
// THLanternAnimationController.m
|
|
// TreeHole
|
|
//
|
|
// Created by iOS on 2023/2/13.
|
|
// Copyright © 2023 CYH. All rights reserved.
|
|
//
|
|
|
|
#import "THLanternAnimationController.h"
|
|
#import "THLanternScrollView.h"
|
|
#import "THHomeHotPartyView.h"
|
|
|
|
#import "BottleDetialController.h"
|
|
#import "BottleTypePickerViewController.h"
|
|
#import "BottleReadView.h"
|
|
//#import "THBottleInfoModel.h"
|
|
#import "BottleDetialController.h"
|
|
#import "InviteCodeViewController.h"
|
|
#import "BottleService.h"
|
|
|
|
@interface THLanternAnimationController ()
|
|
|
|
//@property(nonatomic, strong)UIView *ableView;
|
|
//@property(nonatomic, strong)UIImageView *firstImgView;
|
|
//@property(nonatomic, strong)UIImageView *secondImgView;
|
|
//@property(nonatomic, strong)UIImageView *thirdImgView;
|
|
|
|
@property(nonatomic, strong)THHomeHotPartyView *hotPartyView;
|
|
|
|
@property(nonatomic, strong)QMUIButton *attBtn;
|
|
@property(nonatomic, strong)QMUIButton *randomBtn;
|
|
|
|
@property(nonatomic, strong)THLanternScrollView *scrollView;
|
|
|
|
@end
|
|
|
|
@implementation THLanternAnimationController
|
|
|
|
- (BOOL)mt_nagationBarTransparent{
|
|
return YES;
|
|
}
|
|
|
|
//MARK: - Event
|
|
///随机查看
|
|
- (void)showRandomBottle {
|
|
WeakSelf(self);
|
|
// [SVProgressHUD showWithStatus:nil];
|
|
|
|
BottleReadView *readView = [BottleReadView showDetailWithBottleInfo:nil Views:self.view isHome:YES shouldHideBottleAction:^(bool shouldHide) {
|
|
if (shouldHide) {
|
|
// firstInfoModel.cover = nil;
|
|
}
|
|
}];
|
|
readView.didLockMoreBottle = ^{
|
|
BottleDetialController *deDetial = [[BottleDetialController alloc]init];
|
|
[weakself.navigationController.navigationController pushViewController:deDetial animated:YES];
|
|
};
|
|
// [readView setDidLockMoreBottle:^{
|
|
//
|
|
// }];
|
|
return;
|
|
/*
|
|
[THNetworkInterfaceService requestSingleRecommendBottleInfoComplete:^(NSDictionary * _Nullable responseDicData, NSError * _Nullable err) {
|
|
if (responseDicData.allKeys.count <= 0) {
|
|
[THNetworkInterfaceService showBottleEmptyAlertViewWithButtonTap:^(UIButton * _Nonnull sender) {
|
|
BottleDetialController *deDetial = [[BottleDetialController alloc]init];
|
|
[weakself.navigationController.navigationController pushViewController:deDetial animated:YES];
|
|
}];
|
|
return;
|
|
}
|
|
BottleDetailInfo *info = [BottleDetailInfo mj_objectWithKeyValues:responseDicData];
|
|
}];
|
|
*/
|
|
}
|
|
|
|
///查看关注
|
|
- (void)showAttentionBottle {
|
|
[BottleReadView showDetailWithAttach];
|
|
}
|
|
|
|
///酒柜页面
|
|
- (void)toBottleGroupsVC {
|
|
BottleDetialController *deDetial = [[BottleDetialController alloc]init];
|
|
[self.navigationController pushViewController:deDetial animated:YES];
|
|
}
|
|
|
|
///领会员
|
|
- (void)toInviteCodeViewController {
|
|
InviteCodeViewController *inviteVC = [InviteCodeViewController new];
|
|
[self.navigationController pushViewController:inviteVC animated:YES];
|
|
}
|
|
|
|
///发布
|
|
- (void)toChooseBottleTypeAndPublishVC {
|
|
WeakSelf(self);
|
|
BottleTypePickerViewController *picker = [BottleTypePickerViewController pickerViewControllerWithCompletion:^(BottleTypePickerViewController * _Nonnull picker, BottleTypeInfo * _Nonnull info) {
|
|
[picker.navigationController dismissViewControllerAnimated:NO completion:^{
|
|
BottlePublishViewController *publishVC = [[BottlePublishViewController alloc] init];
|
|
publishVC.info = info;
|
|
publishVC.publishSucceedAction = ^{
|
|
// if (weakself.info.left_bottle_num > 0) {
|
|
// weakself.info.left_bottle_num --;
|
|
// [weakself reloadHurlBottoleButtonBadge];
|
|
// }
|
|
};
|
|
[weakself.navigationController presentViewController:[[PYNavigationViewController alloc] initWithRootViewController:publishVC] animated:YES completion:nil];
|
|
}];
|
|
}];
|
|
THNavigationController *nav = [[THNavigationController alloc] initWithRootViewController:picker];
|
|
[[PYAppService currentNavigationController] presentViewController:nav animated:YES completion:nil];
|
|
}
|
|
|
|
///参与派对人数
|
|
- (void)requestHotPartyNumber {
|
|
WeakSelf(self);
|
|
[PYHTTPManager postWithPath:@"bottlecount" params:nil callback:^(id _Nullable rsp, NSError * _Nullable error) {
|
|
|
|
CGFloat count = [rsp[@"count"] floatValue];
|
|
if (count >= 10000) {
|
|
weakself.hotPartyView.numberStr = [NSString stringWithFormat:@"%.2f万次参与",count/10000.0];
|
|
}else{
|
|
weakself.hotPartyView.numberStr = [NSString stringWithFormat:@"%f次参与",count];
|
|
}
|
|
}];
|
|
}
|
|
|
|
|
|
//MARK: - Life
|
|
- (void)initSubviews {
|
|
[super initSubviews];
|
|
// 对 subviews 的初始化写在这里
|
|
|
|
WeakSelf(self);
|
|
|
|
_scrollView = [THLanternScrollView creatViewInSuperView:self.view];
|
|
_scrollView.itemTapBlock = ^(UIControl *sender) {
|
|
// NSLog(@"---");
|
|
[weakself showRandomBottle];
|
|
};
|
|
|
|
///酒馆派对火热进行中...
|
|
_hotPartyView = [THHomeHotPartyView creatViewInSuperView:_scrollView];
|
|
_hotPartyView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
|
|
_hotPartyView.layer.cornerRadius = 8;
|
|
[_hotPartyView addTapWithAction:^{
|
|
[weakself toBottleGroupsVC];
|
|
}];
|
|
|
|
QMUIButton *attBtn = [QMUIButton creatButtonWithFontSize:14 fontWeight:UIFontWeightMedium textColorHex:@"#16112F" textState:UIControlStateNormal inSuperView:self.view];
|
|
attBtn.backgroundColor = UIColorMakeWithHex(@"#FFBA8B");
|
|
attBtn.cornerRadius = QMUIButtonCornerRadiusAdjustsBounds;
|
|
[attBtn setTitle:@"只看关注" forState:UIControlStateNormal];
|
|
attBtn.contentEdgeInsets = UIEdgeInsetsMake(8, 22, 8, 22);
|
|
[attBtn addTapWithAction:^{
|
|
[weakself showAttentionBottle];
|
|
}];
|
|
_attBtn = attBtn;
|
|
|
|
QMUIButton *randomBtn = [QMUIButton creatButtonWithFontSize:14 fontWeight:UIFontWeightMedium textColorHex:@"#16112F" textState:UIControlStateNormal inSuperView:self.view];
|
|
randomBtn.backgroundColor = UIColorMakeWithHex(@"#FFBA8B");
|
|
randomBtn.cornerRadius = QMUIButtonCornerRadiusAdjustsBounds;
|
|
[randomBtn setTitle:@"随机窥探" forState:UIControlStateNormal];
|
|
randomBtn.contentEdgeInsets = UIEdgeInsetsMake(8, 22, 8, 22);
|
|
[randomBtn addTapWithAction:^{
|
|
[weakself showRandomBottle];
|
|
}];
|
|
_randomBtn = randomBtn;
|
|
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// 对 self.view 的操作写在这里
|
|
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
|
|
[self requestHotPartyNumber];
|
|
|
|
[self.scrollView starScrollAnimate];
|
|
}
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
[super viewDidAppear:animated];
|
|
}
|
|
|
|
- (void)viewDidLayoutSubviews {
|
|
[super viewDidLayoutSubviews];
|
|
|
|
self.scrollView.frame = self.view.bounds;
|
|
|
|
self.hotPartyView.frame = CGRectMake(20, self.qmui_navigationBarMaxYInViewCoordinator + 5, self.view.qmui_width - 20 * 2, 49);
|
|
|
|
[self.attBtn sizeToFit];
|
|
self.attBtn.qmui_right = self.view.qmui_width * 0.5 - 22;
|
|
self.attBtn.qmui_bottom = self.view.qmui_height - TabBarHeight - 25;
|
|
|
|
[self.randomBtn sizeToFit];
|
|
self.randomBtn.qmui_left = self.view.qmui_width * 0.5 + 22;
|
|
self.randomBtn.qmui_bottom = self.attBtn.qmui_bottom;
|
|
}
|
|
|
|
- (void)didInitialize {
|
|
[super didInitialize];
|
|
// init 时做的事情请写在这里
|
|
|
|
self.hidesBottomBarWhenPushed = NO;
|
|
}
|
|
|
|
|
|
|
|
- (void)setupNavigationItems {
|
|
[super setupNavigationItems];
|
|
self.title = @"基地推荐";
|
|
|
|
WeakSelf(self);
|
|
QMUIButton *leftItemBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImageMake(@"TH_GetVip_nav") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] title:@""];
|
|
[leftItemBtn addTapWithAction:^{
|
|
[weakself toInviteCodeViewController];
|
|
}];
|
|
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftItemBtn];
|
|
|
|
QMUIButton *rightItemBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImageMake(@"TH_navItemBottlePublic") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] title:@""];
|
|
[rightItemBtn addTapWithAction:^{
|
|
[weakself toChooseBottleTypeAndPublishVC];
|
|
}];
|
|
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightItemBtn];
|
|
|
|
}
|
|
|
|
//MARK: - Other
|
|
/*
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// 对 self.view 的操作写在这里
|
|
|
|
UIView *ableView = [UIView creatViewInSuperView:self.view];
|
|
ableView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 240);
|
|
_ableView = ableView;
|
|
|
|
UIImageView *firstItemImgView = [UIImageView creatViewInSuperView:ableView];
|
|
firstItemImgView.frame = CGRectMake(0, 0, 80, 80);
|
|
firstItemImgView.backgroundColor = UIColor.redColor;
|
|
firstItemImgView.image = UIImageMake(@"TH_lantern_left");
|
|
_firstImgView = firstItemImgView;
|
|
|
|
UIImageView *secondItemImgView = [UIImageView creatViewInSuperView:ableView];
|
|
secondItemImgView.image = UIImageMake(@"TH_lantern_rigth");
|
|
secondItemImgView.frame = CGRectMake(0, ableView.qmui_height - 80, 80, 80);
|
|
_secondImgView = secondItemImgView;
|
|
|
|
UIImageView *thirdItemImgView = [UIImageView creatViewInSuperView:ableView];
|
|
thirdItemImgView.image = UIImageMake(@"TH_lantern_rigth");
|
|
thirdItemImgView.frame = CGRectMake(self.ableView.qmui_width - 80, 80, 80, 80);
|
|
_thirdImgView = thirdItemImgView;
|
|
|
|
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
|
|
basicAnimation.fromValue=[NSNumber numberWithFloat:SCREEN_HEIGHT];
|
|
basicAnimation.toValue=[NSNumber numberWithFloat:-240];
|
|
basicAnimation.duration=5;
|
|
basicAnimation.repeatCount = MAXFLOAT;
|
|
[ableView.layer addAnimation:basicAnimation forKey:@"position.y"];
|
|
|
|
}
|
|
|
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
|
|
UITouch *touch = [touches anyObject];
|
|
CGPoint point = [touch locationInView:self.view];
|
|
|
|
CGPoint redPoint = [self.firstImgView.layer.presentationLayer convertPoint:point fromLayer:self.view.layer];
|
|
CGPoint yellowPoint = [self.secondImgView.layer.presentationLayer convertPoint:point fromLayer:self.view.layer];
|
|
if ([self.firstImgView.layer.presentationLayer containsPoint:redPoint]) {
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"point red" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
|
|
[alert show];
|
|
}
|
|
if ([self.secondImgView.layer.presentationLayer containsPoint:yellowPoint]) {
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"point yellow" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
|
|
[alert show];
|
|
}
|
|
if ([self.thirdImgView.layer.presentationLayer containsPoint:yellowPoint]) {
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"point greed" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
|
|
[alert show];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)addAnimationGroupWithIdentify:(NSString *)identify fromScale:(CGFloat)fromScale toScale:(CGFloat)toScale scaleDuration:(CGFloat)scaleDuration positionPath:(UIBezierPath *)bezierPath positionDuration:(CGFloat)pathDuration forView:(UIView *)view {
|
|
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
|
|
animation.fromValue=[NSNumber numberWithFloat:fromScale];
|
|
animation.toValue=[NSNumber numberWithFloat:toScale];
|
|
animation.duration=scaleDuration;
|
|
// animation.autoreverses=YES;
|
|
// animation.removedOnCompletion=NO;
|
|
// animation.repeatCount=MAXFLOAT;
|
|
// animation.fillMode=kCAFillModeForwards;
|
|
|
|
//4.设置关键帧动画
|
|
//2.绘制路线
|
|
// UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
|
|
// [bezierPath moveToPoint:CGPointMake(orFrame.origin.x, orFrame.origin.y)];
|
|
// [bezierPath addCurveToPoint:CGPointMake(orFrame.origin.x + 50, 0) controlPoint1:CGPointMake(orFrame.origin.x + 50, orFrame.origin.y - 200) controlPoint2:CGPointMake(orFrame.origin.x - 50, orFrame.origin.y - 400)];
|
|
|
|
CAShapeLayer *pathLayer = [CAShapeLayer layer];
|
|
pathLayer.path = bezierPath.CGPath;
|
|
pathLayer.fillColor = [UIColor clearColor].CGColor;
|
|
pathLayer.strokeColor = [UIColor redColor].CGColor;
|
|
pathLayer.lineWidth = 3.0f;
|
|
[self.view.layer addSublayer:pathLayer];
|
|
|
|
CAKeyframeAnimation *animation_key = [CAKeyframeAnimation animation];
|
|
animation_key.keyPath = @"position";
|
|
// animation_key.duration = 5.0;
|
|
// animation_key.repeatCount = MAXFLOAT;
|
|
animation_key.path = bezierPath.CGPath;
|
|
// animation_key.rotationMode = kCAAnimationRotateAuto; //设置根据曲线的切线自动旋转,让动画更加真实
|
|
|
|
CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
|
|
groupAnimation.animations = @[animation, animation_key];
|
|
groupAnimation.duration = 5.0;
|
|
groupAnimation.repeatCount = MAXFLOAT;
|
|
[view.layer addAnimation:groupAnimation forKey:identify];
|
|
}
|
|
- (void)moveAnimation {
|
|
|
|
CGRect orFrame = CGRectMake(50, self.view.qmui_height, 80, 100);
|
|
|
|
UIImageView *lanternImgView = [UIImageView creatViewInSuperView:self.view];
|
|
lanternImgView.image = UIImageMake(@"TH_lantern_left");
|
|
lanternImgView.frame = orFrame;
|
|
|
|
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
|
|
animation.fromValue=[NSNumber numberWithFloat:1.0];
|
|
animation.toValue=[NSNumber numberWithFloat:0.2];
|
|
animation.duration=6.0;
|
|
animation.autoreverses=YES;
|
|
animation.removedOnCompletion=NO;
|
|
animation.repeatCount=MAXFLOAT;
|
|
animation.fillMode=kCAFillModeForwards;
|
|
// [view.layer addAnimation:animation forKey:@"zoom"];
|
|
|
|
//4.设置关键帧动画
|
|
//2.绘制路线
|
|
UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
|
|
[bezierPath moveToPoint:CGPointMake(orFrame.origin.x, orFrame.origin.y)];
|
|
[bezierPath addCurveToPoint:CGPointMake(orFrame.origin.x + 50, 0) controlPoint1:CGPointMake(orFrame.origin.x + 50, orFrame.origin.y - 200) controlPoint2:CGPointMake(orFrame.origin.x - 50, orFrame.origin.y - 400)];
|
|
|
|
CAShapeLayer *pathLayer = [CAShapeLayer layer];
|
|
pathLayer.path = bezierPath.CGPath;
|
|
pathLayer.fillColor = [UIColor clearColor].CGColor;
|
|
pathLayer.strokeColor = [UIColor redColor].CGColor;
|
|
pathLayer.lineWidth = 3.0f;
|
|
[self.view.layer addSublayer:pathLayer];
|
|
|
|
CAKeyframeAnimation *animation_key = [CAKeyframeAnimation animation];
|
|
animation_key.repeatCount = MAXFLOAT;
|
|
animation_key.keyPath = @"position";
|
|
animation_key.duration = 5.0;
|
|
animation_key.path = bezierPath.CGPath;
|
|
// animation_key.rotationMode = kCAAnimationRotateAuto; //设置根据曲线的切线自动旋转,让动画更加真实
|
|
|
|
CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
|
|
groupAnimation.animations = @[animation, animation_key];
|
|
groupAnimation.duration = 5.0;
|
|
groupAnimation.repeatCount = MAXFLOAT;
|
|
[lanternImgView.layer addAnimation:groupAnimation forKey:@"groupAnimation"];
|
|
|
|
|
|
// [lanternImgView.layer addAnimation:animation_key forKey:nil];
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
|
// UITouch *touch = [touches anyObject];
|
|
// CGPoint point = [touch locationInView:self.view];
|
|
//
|
|
// //方案一
|
|
//// if (CGRectContainsPoint(self.testview.layer.presentationLayer.frame, point)) {
|
|
//// [self clickPresntationLayer];
|
|
//// }
|
|
//
|
|
// //方案二
|
|
// if ([self.testview.layer.presentationLayer hitTest:point] != nil) {
|
|
// [self clickPresntationLayer];
|
|
// }
|
|
//}
|
|
|
|
//- (void)clickPresntationLayer{
|
|
// self.testview.backgroundColor = [UIColor colorWithRed:(arc4random()%255/255.0) green:(arc4random()%255/255.0) blue:(arc4random()%255/255.0) alpha:1.0];
|
|
//}
|
|
/*
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// 对 self.view 的操作写在这里
|
|
|
|
// [self setupUpemitterLayer];
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
UIImageView *lanternImgView = [UIImageView creatViewInSuperView:self.view];
|
|
lanternImgView.userInteractionEnabled = YES;
|
|
lanternImgView.image = UIImageMake(@"TH_lantern_left");
|
|
[lanternImgView addTapWithAction:^{
|
|
|
|
}];
|
|
CGFloat orWH = cyh_arc4random(20, 100);
|
|
lanternImgView.frame = CGRectMake(cyh_arc4random(0, SCREEN_WIDTH), SCREEN_HEIGHT, orWH, orWH);
|
|
|
|
CGFloat transX = lanternImgView.frame.origin.x;
|
|
// CGFloat w_2 = SCREEN_WIDTH * 0.5;
|
|
// CGFloat transX = cyh_arc4random(0, w_2);
|
|
// if (i > 10) {
|
|
// transX = cyh_arc4random(w_2, SCREEN_WIDTH);
|
|
// }
|
|
|
|
[UIView animateWithDuration:10 delay:cyh_arc4random(0, 20) options:UIViewAnimationOptionCurveEaseOut animations:^{
|
|
[UIView setAnimationRepeatCount:MAXFLOAT];
|
|
CGFloat wh = orWH * cyh_arc4random(0.3, 1);
|
|
lanternImgView.frame = CGRectMake(transX, 0, wh, wh);
|
|
} completion:^(BOOL finished) {
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
//X轴上随机速度
|
|
|
|
int screenW_2 = SCREEN_WIDTH*0.5;
|
|
//产生从X~Y的随机数:K= rand() % (Y-X+1) + X
|
|
// cyh_arc4random(0, SCREEN_WIDTH);
|
|
CGFloat x = ((SCREEN_WIDTH - 80) / 4) * i;
|
|
// CGFloat y = rand() % (SCREEN_HEIGHT-0+1) + 0;
|
|
|
|
CGFloat viewWH = cyh_arc4random(40, 100);
|
|
|
|
CGRect orFrame = CGRectMake(x, SCREEN_HEIGHT, viewWH, viewWH);
|
|
UIImageView *lanternImgView = [UIImageView creatViewInSuperView:self.view];
|
|
lanternImgView.userInteractionEnabled = YES;
|
|
[lanternImgView addTapWithAction:^{
|
|
NSLog(@"点击了---");
|
|
}];
|
|
lanternImgView.image = UIImageMake(@"TH_lantern_left");
|
|
lanternImgView.frame = orFrame;
|
|
UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
|
|
[bezierPath moveToPoint:CGPointMake(orFrame.origin.x, orFrame.origin.y)];
|
|
|
|
[bezierPath addCurveToPoint:
|
|
CGPointMake(cyh_arc4random(0, SCREEN_WIDTH), 0)
|
|
controlPoint1:CGPointMake(cyh_arc4random(0, SCREEN_WIDTH), SCREEN_HEIGHT*0.6)
|
|
controlPoint2:CGPointMake(cyh_arc4random(0, SCREEN_WIDTH), SCREEN_HEIGHT*0.3)];
|
|
[self addAnimationGroupWithIdentify:[NSString stringWithFormat:@"GroupAnimation_%d",i] fromScale:1 toScale:0.3 scaleDuration:6 positionPath:bezierPath positionDuration:5 forView:lanternImgView];
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
@end
|