|
//
// AnimationWelcomeController.m
// ThePaperBase
//
// Created by scar1900 on 15/12/18.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "AnimationWelcomeController.h"
#import "IFTTTJazzHands.h"
#import "StyledPageControl.h"
#define firstDuration 1.5f
#define firstTimeInterval 0.01f
#define standardOffset [[UIScreen mainScreen]bounds].size.height/3
#define waterDropSourceRect CGRectMake(self.view.bounds.size.width/2-4, 15, 8, 27/2)
#define waterDropDownRect CGRectMake(self.view.bounds.size.width/2-4, standardOffset*2, 8, 27/2)
#define transformOffset 45
#define waterformOffset 5
#define animationDuration 0.15
@interface AnimationWelcomeController ()<UIGestureRecognizerDelegate> {
CGFloat timerCount;
CGPoint startTouch;
CGFloat swipeStandardOffset;
CGRect birdsRect;
}
@property(nonatomic, strong)UIImageView *backImageView;
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)UIView *cloudBack;
@property(nonatomic, strong)UIImageView *waterDrop;
@property(nonatomic, strong)IFTTTAnimator *waterDropAnimator;
@property(nonatomic, strong)UIImageView *cloud_1;
@property(nonatomic, strong)UIImageView *cloud_2;
@property(nonatomic, strong)UIImageView *cloud_3;
@property(nonatomic, strong)UIImageView *cloud_4;
@property(nonatomic, strong)UIImageView *cloud_5;
@property(nonatomic, strong)UIImageView *cloud_6;
@property(nonatomic, strong)UIImageView *cloud_7;
@property(nonatomic, strong)UIImageView *cloud_8;
@property(nonatomic, strong)UIImageView *smallFish;
@property(nonatomic, strong)UIView *smallFishPathView;
@property(nonatomic, strong)IFTTTPathPositionAnimation *smallFishAnimation;
@property(nonatomic, strong)IFTTTPathPositionAnimation *fishBowlPathAnimation;
@property(nonatomic, strong)CAShapeLayer *smallFishPathLayer;
@property(nonatomic, strong)UIImageView *textImageView1;
@property(nonatomic, strong)UIImageView *textImageView2;
@property(nonatomic, strong)UIImageView *fishBowl;
@property(nonatomic, strong)UIView *fishBowlBlackView;
@property(nonatomic, strong)UIView *fishBowlPathView;
@property(nonatomic, strong)CAShapeLayer *fishBowlPathLayer;
@property(nonatomic, strong)UIImageView *line_in;
@property(nonatomic, strong)UIImageView *line_out;
@property(nonatomic, strong)UIImageView *fishBowlLidView;
@property(nonatomic, strong)UIImageView *water1;
@property(nonatomic, strong)UIImageView *water2;
@property(nonatomic, strong)UIImageView *water3;
@property(nonatomic, strong)UIImageView *bubble;
@property(nonatomic, strong)UIPanGestureRecognizer *pangesture;
@property(nonatomic, strong)IFTTTAnimator *gestureAnimator1;
@property(nonatomic, strong)IFTTTAnimator *gestureAnimator2;
@property(nonatomic, assign)NSInteger currentIndex;
@property(nonatomic, strong)UIImageView *bigFish;
@property(nonatomic, strong)UIImageView *birds;
@property(nonatomic, strong)UISwipeGestureRecognizer *leftSwipeGesture;
@property(nonatomic, strong)StyledPageControl *pageControl; //页码指示器
@end
@implementation AnimationWelcomeController
- (void)viewDidLoad {
[super viewDidLoad];
swipeStandardOffset = -self.view.bounds.size.width;
self.view.backgroundColor = [UIColor clearColor];
self.backImageView = [[UIImageView alloc]initWithImage:Image(@"animationImages/backImage.png")];
self.backImageView.frame = self.view.bounds;
[self.view addSubview:self.backImageView];
self.backView = [UIView new];
self.backView.frame = self.view.bounds;
self.backView.backgroundColor = [self colorWithHexString:@"0xefdbcb"];
self.backView.alpha = 0.9f;
[self.view addSubview:self.backView];
self.cloudBack = [UIView new];
self.cloudBack.backgroundColor = [UIColor clearColor];
self.cloudBack.frame =self.backView.bounds;
[self.backView addSubview:self.cloudBack];
timerCount = 0;
// Do any additional setup after loading the view, typically from a nib.
[self addAnimatorView];
[self configureAnimatorView];
[self addtimer];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
#pragma mark - add animator view
- (void)addAnimatorView {
self.waterDrop = [[UIImageView alloc]initWithImage:Image(@"animationImages/waterDrop.png")];
self.waterDrop.frame = waterDropSourceRect;
[self.backView addSubview:self.waterDrop];
self.cloud_1 = [[UIImageView alloc]initWithImage:Image(@"animationImages/cloud_1.png")];
self.cloud_1.frame = CGRectMake(self.view.bounds.size.width/2-303/4,
waterDropDownRect.origin.y-11,
303/2,
91/2);
self.cloud_1.hidden = YES;
[self.backView addSubview:self.cloud_1];
if (IS_IPHONE_6P) {
self.textImageView1 = [[UIImageView alloc]initWithImage:Image(@"animationImages/textImage_1_i6P.png")];
self.textImageView1.frame = CGRectMake(self.view.bounds.size.width/2-177/4, 64/2, 177/2, 478/2);
}else if (IS_IPHONE_6) {
self.textImageView1 = [[UIImageView alloc]initWithImage:Image(@"animationImages/textImage_1_i6.png")];
self.textImageView1.frame = CGRectMake(self.view.bounds.size.width/2-160/4, 64/2, 160/2, 434/2);
}else {
self.textImageView1 = [[UIImageView alloc]initWithImage:Image(@"animationImages/textImage_1.png")];
self.textImageView1.frame = CGRectMake(self.view.bounds.size.width/2-54/2, 64/2, 108/2, 311/2);
}
self.textImageView1.alpha = 0.0f;
[self.backView addSubview:self.textImageView1];
if (IS_IPHONE_6P) {
self.textImageView2 = [[UIImageView alloc]initWithImage:Image(@"animationImages/textImage_2_i6P.png")];
self.textImageView2.frame = CGRectMake(self.view.bounds.size.width/2-177/4, 64/2, 177/2, 372/2);
}else if (IS_IPHONE_6) {
self.textImageView2 = [[UIImageView alloc]initWithImage:Image(@"animationImages/textImage_2_i6.png")];
self.textImageView2.frame = CGRectMake(self.view.bounds.size.width/2-160/4, 64/2, 160/2, 337/2);
}else {
self.textImageView2 = [[UIImageView alloc]initWithImage:Image(@"animationImages/textImage_2.png")];
self.textImageView2.frame = CGRectMake(self.view.bounds.size.width/2-54/2, 64/2, 108/2, 242/2);
}
self.textImageView2.alpha = 0.0f;
[self.backView addSubview:self.textImageView2];
self.fishBowl = [[UIImageView alloc]initWithImage:Image(@"animationImages/fishBowl.png")];
self.fishBowl.frame = CGRectMake(self.view.bounds.size.width/2-372/4,
CGRectGetMinY(self.cloud_1.frame)+15-269/2,
372/2,
269/2);
self.fishBowl.alpha = 0.0f;
[self.backView addSubview:self.fishBowl];
}
- (void)addSmallFish {
self.smallFishPathLayer = [self fishePathLayer];
self.smallFishPathView = [UIView new];
[self.backView addSubview:self.smallFishPathView];
[self.smallFishPathView.layer addSublayer:self.smallFishPathLayer];
self.smallFishPathView.frame = CGRectMake(CGRectGetMaxX(self.cloud_1.frame)-CGRectGetWidth(self.cloud_1.frame)/2-49,
CGRectGetMinY(self.cloud_1.frame)-31,
49, 31);
self.smallFish = [[UIImageView alloc]initWithImage:Image(@"animationImages/smallFish.png")];
self.smallFish.frame = CGRectMake(0,
0,
49,
31);
[self.smallFishPathView addSubview:self.smallFish];
self.smallFishAnimation = [IFTTTPathPositionAnimation animationWithView:self.smallFish path:self.smallFishPathLayer.path];
[self.smallFishAnimation addKeyframeForTime:firstDuration/4
animationProgress:0
withEasingFunction:IFTTTEasingFunctionEaseOutQuad];
[self.smallFishAnimation addKeyframeForTime:firstDuration
animationProgress:1
withEasingFunction:IFTTTEasingFunctionEaseInQuad];
[self.waterDropAnimator addAnimation:self.smallFishAnimation];
IFTTTLayerStrokeEndAnimation *fishPathAnimation = [IFTTTLayerStrokeEndAnimation animationWithLayer:self.smallFishPathLayer];
[fishPathAnimation addKeyframeForTime:firstDuration/4
strokeEnd:0
withEasingFunction:IFTTTEasingFunctionEaseOutQuad];
[fishPathAnimation addKeyframeForTime:firstDuration
strokeEnd:1
withEasingFunction:IFTTTEasingFunctionEaseInQuad];
[self.waterDropAnimator addAnimation:fishPathAnimation];
IFTTTAlphaAnimation *fishBowlAlphaAnimation = [IFTTTAlphaAnimation animationWithView:self.fishBowl];
[fishBowlAlphaAnimation addKeyframeForTime:firstDuration/4 alpha:0.f];
[fishBowlAlphaAnimation addKeyframeForTime:firstDuration alpha:1.0f];
[self.waterDropAnimator addAnimation:fishBowlAlphaAnimation];
// [self addFishBowl];
[self addFishBowlLid];
}
- (void)addFishBowl {
self.fishBowlPathLayer = [self fishBowlPathLayer];
self.fishBowlPathView = [UIView new];
[self.backView addSubview:self.fishBowlPathView];
[self.fishBowlPathView.layer addSublayer:self.fishBowlPathLayer];
self.fishBowlPathView.frame = CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-10, CGRectGetMinY(self.fishBowl.frame), 1, 1);
self.fishBowlBlackView = [UIView new];
[self.backView addSubview:self.fishBowlBlackView];
self.fishBowlBlackView.frame = CGRectMake(0,
0,
1,
1);
[self.fishBowlPathView addSubview:self.fishBowlBlackView];
self.fishBowlPathAnimation = [IFTTTPathPositionAnimation animationWithView:self.fishBowlBlackView path:self.fishBowlPathLayer.path];
[self.fishBowlPathAnimation addKeyframeForTime:firstDuration/4
animationProgress:0
withEasingFunction:IFTTTEasingFunctionEaseOutQuad];
[self.fishBowlPathAnimation addKeyframeForTime:firstDuration
animationProgress:1
withEasingFunction:IFTTTEasingFunctionEaseInQuad];
[self.waterDropAnimator addAnimation:self.fishBowlPathAnimation];
IFTTTLayerStrokeEndAnimation *bowlPathAnimation = [IFTTTLayerStrokeEndAnimation animationWithLayer:self.fishBowlPathLayer];
[bowlPathAnimation addKeyframeForTime:firstDuration/4
strokeEnd:0
withEasingFunction:IFTTTEasingFunctionEaseOutQuad];
[bowlPathAnimation addKeyframeForTime:firstDuration
strokeEnd:1
withEasingFunction:IFTTTEasingFunctionEaseInQuad];
[self.waterDropAnimator addAnimation:bowlPathAnimation];
}
- (void)addFishBowlLid {
self.fishBowlLidView = [[UIImageView alloc]initWithImage:Image(@"animationImages/fishBowlLid.png")];
self.fishBowlLidView.frame = CGRectMake(CGRectGetMinX(self.fishBowl.frame)+6, CGRectGetMinY(self.fishBowl.frame)-11, 349/2, 11);
self.fishBowlLidView.alpha = 0.0f;
[self.backView addSubview:self.fishBowlLidView];
IFTTTScaleAnimation *fishBowlLidScaleAnimation = [IFTTTScaleAnimation animationWithView:self.fishBowlLidView];
[fishBowlLidScaleAnimation addKeyframeForTime:firstDuration*0.5
scale:0.1f];
[fishBowlLidScaleAnimation addKeyframeForTime:firstDuration*10/12
scale:1.0f];
[fishBowlLidScaleAnimation addKeyframeForTime:firstDuration*11/12
scale:0.8f];
[fishBowlLidScaleAnimation addKeyframeForTime:firstDuration
scale:1.0f];
[self.waterDropAnimator addAnimation:fishBowlLidScaleAnimation];
self.line_in = [[UIImageView alloc]initWithImage:Image(@"animationImages/line_in.png")];
self.line_in.frame = CGRectMake(CGRectGetMinX(self.fishBowl.frame)+116/2, CGRectGetMinY(self.fishBowl.frame)+26, 228/2, 198/2);
[self.view addSubview:self.line_in];
IFTTTAlphaAnimation *line_inAlphaAnimation = [IFTTTAlphaAnimation animationWithView:self.line_in];
[line_inAlphaAnimation addKeyframeForTime:firstDuration*3/4 alpha:0.0f];
[line_inAlphaAnimation addKeyframeForTime:firstDuration alpha:1.0f];
[self.waterDropAnimator addAnimation:line_inAlphaAnimation];
self.line_out = [[UIImageView alloc]initWithImage:Image(@"animationImages/line_out.png")];
self.line_out.frame = CGRectMake(CGRectGetMinX(self.fishBowl.frame), CGRectGetMinY(self.fishBowl.frame)+84/2, 386/2, 101);
[self.view addSubview:self.line_out];
IFTTTAlphaAnimation *line_outAlphaAnimation = [IFTTTAlphaAnimation animationWithView:self.line_out];
[line_outAlphaAnimation addKeyframeForTime:firstDuration*3/4 alpha:0.0f];
[line_outAlphaAnimation addKeyframeForTime:firstDuration alpha:1.0f];
[self.waterDropAnimator addAnimation:line_outAlphaAnimation];
}
- (void)addWater {
self.water1 = [[UIImageView alloc]initWithImage:Image(@"animationImages/water1.png")];
self.water1.frame = CGRectMake(CGRectGetWidth(self.backView.bounds)/2-369/4, CGRectGetMaxY(self.fishBowl.frame), 369/2, 0);
self.water1.contentMode = UIViewContentModeCenter;
self.water1.clipsToBounds = YES;
[self.backView addSubview:self.water1];
IFTTTFrameAnimation *frameAnimation = [IFTTTFrameAnimation animationWithView:self.water1];
[frameAnimation addKeyframeForTime:firstDuration/4
frame:CGRectMake(CGRectGetWidth(self.backView.bounds)/2-369/4, CGRectGetMaxY(self.fishBowl.frame), 369/2, 0)];
[frameAnimation addKeyframeForTime:firstDuration/2
frame:CGRectMake(CGRectGetWidth(self.backView.bounds)/2-369/4, CGRectGetMaxY(self.fishBowl.frame)-188/2, 369/2, 188/2)];
[self.waterDropAnimator addAnimation:frameAnimation];
self.water2 = [[UIImageView alloc]initWithImage:Image(@"animationImages/water2.png")];
self.water2.frame = CGRectMake(CGRectGetWidth(self.backView.bounds)/2-371/4, CGRectGetMaxY(self.fishBowl.frame)-216/2, 371/2, 216/2);
[self.backView addSubview:self.water2];
[self.backView insertSubview:self.water2 belowSubview:self.water1];
IFTTTFrameAnimation *water2frameAnimation = [IFTTTFrameAnimation animationWithView:self.water2];
[water2frameAnimation addKeyframeForTime:firstDuration/2
frame:CGRectMake(CGRectGetWidth(self.backView.bounds)/2-371/4, CGRectGetMaxY(self.fishBowl.frame)-188/2, 371/2, 0)];
[water2frameAnimation addKeyframeForTime:firstDuration*4/7
frame:CGRectMake(CGRectGetWidth(self.backView.bounds)/2-371/4, CGRectGetMaxY(self.fishBowl.frame)-225/2, 371/2, 216/2)];
[water2frameAnimation addKeyframeForTime:firstDuration*5/7
frame:CGRectMake(CGRectGetWidth(self.backView.bounds)/2-371/4, CGRectGetMaxY(self.fishBowl.frame)-216/2, 371/2, 216/2)];
[self.waterDropAnimator addAnimation:water2frameAnimation];
self.water3 = [[UIImageView alloc]initWithImage:Image(@"animationImages/water3.png")];
self.water3.frame = CGRectMake(CGRectGetWidth(self.backView.bounds)/2-372/4, CGRectGetMaxY(self.fishBowl.frame)-216/2, 372/2, 241/2);
[self.backView addSubview:self.water3];
[self.backView insertSubview:self.water3 belowSubview:self.water2];
IFTTTFrameAnimation *water3frameAnimation = [IFTTTFrameAnimation animationWithView:self.water3];
[water3frameAnimation addKeyframeForTime:firstDuration*5/7
frame:CGRectMake(CGRectGetWidth(self.backView.bounds)/2-372/4, CGRectGetMaxY(self.fishBowl.frame)-216/2, 372/2, 0)];
[water3frameAnimation addKeyframeForTime:firstDuration*6/7
frame:CGRectMake(CGRectGetWidth(self.backView.bounds)/2-372/4, CGRectGetMaxY(self.fishBowl.frame)-247/2, 372/2, 241/2)];
[water3frameAnimation addKeyframeForTime:firstDuration
frame:CGRectMake(CGRectGetWidth(self.backView.bounds)/2-372/4, CGRectGetMaxY(self.fishBowl.frame)-241/2, 372/2, 241/2)];
[self.waterDropAnimator addAnimation:water3frameAnimation];
}
- (void)addBubble {
self.bubble = [[UIImageView alloc]initWithImage:Image(@"animationImages/bubble.png")];
self.bubble.frame = CGRectMake(CGRectGetMinX(self.fishBowl.frame),
CGRectGetMinY(self.fishBowl.frame)+30,
97/2,
152/2);
self.bubble.contentMode = UIViewContentModeCenter;
self.bubble.clipsToBounds = YES;
[self.backView addSubview:self.bubble];
self.bubble.alpha = 0.0f;
[self.backView insertSubview:self.bubble belowSubview:self.water1];
[self.backView insertSubview:self.bubble belowSubview:self.fishBowl];
IFTTTFrameAnimation *frameAnimation = [IFTTTFrameAnimation animationWithView:self.bubble];
[frameAnimation addKeyframeForTime:firstDuration*5/8
frame:CGRectMake(CGRectGetMinX(self.fishBowl.frame),
CGRectGetMinY(self.fishBowl.frame)+30,
97/2,
15)];
[frameAnimation addKeyframeForTime:firstDuration
frame:CGRectMake(CGRectGetMinX(self.fishBowl.frame)+10,
CGRectGetMinY(self.fishBowl.frame)-40,
97/2,
152/2)];
[self.waterDropAnimator addAnimation:frameAnimation];
IFTTTAlphaAnimation *alphaAnimation = [IFTTTAlphaAnimation animationWithView:self.bubble];
[alphaAnimation addKeyframeForTime:firstDuration*4/5 alpha:1.0f];
[alphaAnimation addKeyframeForTime:firstDuration
alpha:0.0f
withEasingFunction:IFTTTEasingFunctionEaseInQuad];
[self.waterDropAnimator addAnimation:alphaAnimation];
}
- (void)addCloud {
self.cloud_2 = [[UIImageView alloc]initWithImage:Image(@"animationImages/cloud_2.png")];
self.cloud_2.frame = CGRectMake(CGRectGetMinX(self.fishBowl.frame)-40, -30, 166/2, 30);
[self.cloudBack addSubview:self.cloud_2];
IFTTTFrameAnimation *frameAnimation = [IFTTTFrameAnimation animationWithView:self.cloud_2];
[frameAnimation addKeyframeForTime:firstDuration/4
frame:CGRectMake(CGRectGetMinX(self.fishBowl.frame)-40,
-30,
166/2,
30)];
[frameAnimation addKeyframeForTime:firstDuration/2
frame:CGRectMake(CGRectGetMinX(self.fishBowl.frame)-40,
CGRectGetMinY(self.fishBowl.frame)+40,
166/2,
30)];
[frameAnimation addKeyframeForTime:firstDuration*5/8
frame:CGRectMake(CGRectGetMinX(self.fishBowl.frame)-40,
CGRectGetMinY(self.fishBowl.frame)+20,
166/2,
30)];
[frameAnimation addKeyframeForTime:firstDuration*2/3
frame:CGRectMake(CGRectGetMinX(self.fishBowl.frame)-40,
CGRectGetMinY(self.fishBowl.frame)+65/2,
166/2,
30)];
[self.waterDropAnimator addAnimation:frameAnimation];
self.cloud_3 = [[UIImageView alloc]initWithImage:Image(@"animationImages/cloud_3.png")];
self.cloud_3.frame = CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-155/2, -30, 251/2, 91/2);
[self.cloudBack addSubview:self.cloud_3];
[self.cloudBack insertSubview:self.cloud_3 belowSubview:self.cloud_2];
IFTTTFrameAnimation *cloud3frameAnimation = [IFTTTFrameAnimation animationWithView:self.cloud_3];
[cloud3frameAnimation addKeyframeForTime:firstDuration/3
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-155/2,
-91/2,
251/2,
91/2)];
[cloud3frameAnimation addKeyframeForTime:firstDuration/2
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-155/2,
CGRectGetMinY(self.fishBowl.frame)+90,
251/2,
91/2)];
[cloud3frameAnimation addKeyframeForTime:firstDuration*5/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-155/2,
CGRectGetMinY(self.fishBowl.frame)+60,
251/2,
91/2)];
[cloud3frameAnimation addKeyframeForTime:firstDuration*2/3
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-155/2,
CGRectGetMinY(self.fishBowl.frame)+75,
251/2,
91/2)];
[self.waterDropAnimator addAnimation:cloud3frameAnimation];
self.cloud_4 = [[UIImageView alloc]initWithImage:Image(@"animationImages/cloud_4.png")];
self.cloud_4.frame = CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-112/2, -48/2, 198/2, 48/2);
[self.cloudBack addSubview:self.cloud_4];
[self.cloudBack insertSubview:self.cloud_4 belowSubview:self.cloud_3];
IFTTTFrameAnimation *cloud4frameAnimation = [IFTTTFrameAnimation animationWithView:self.cloud_4];
[cloud4frameAnimation addKeyframeForTime:firstDuration/3+0.02
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-112/2,
-24,
198/2, 48/2)];
[cloud4frameAnimation addKeyframeForTime:firstDuration*5/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-112/2,
CGRectGetMinY(self.fishBowl.frame)+65,
198/2, 48/2)];
[cloud4frameAnimation addKeyframeForTime:firstDuration*6/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-112/2,
CGRectGetMinY(self.fishBowl.frame)+40,
198/2, 48/2)];
[cloud4frameAnimation addKeyframeForTime:firstDuration*7/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-112/2,
CGRectGetMinY(self.fishBowl.frame)+52,
198/2, 48/2)];
[self.waterDropAnimator addAnimation:cloud4frameAnimation];
self.cloud_5 = [[UIImageView alloc]initWithImage:Image(@"animationImages/cloud_5.png")];
self.cloud_5.frame = CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-39, -33, 143/2, 33);
[self.cloudBack addSubview:self.cloud_5];
[self.cloudBack insertSubview:self.cloud_5 belowSubview:self.cloud_4];
IFTTTFrameAnimation *cloud5frameAnimation = [IFTTTFrameAnimation animationWithView:self.cloud_5];
[cloud5frameAnimation addKeyframeForTime:firstDuration*1/2
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-39,
-33,
143/2, 33)];
[cloud5frameAnimation addKeyframeForTime:firstDuration*6/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-39,
CGRectGetMinY(self.fishBowl.frame)+30,
143/2, 33)];
[cloud5frameAnimation addKeyframeForTime:firstDuration*7/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-39,
CGRectGetMinY(self.fishBowl.frame)+10,
143/2, 33)];
[cloud5frameAnimation addKeyframeForTime:firstDuration
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-39,
CGRectGetMinY(self.fishBowl.frame)+19,
143/2, 33)];
[self.waterDropAnimator addAnimation:cloud5frameAnimation];
self.cloud_6 = [[UIImageView alloc]initWithImage:Image(@"animationImages/cloud_6.png")];
self.cloud_6.frame = CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-30, CGRectGetMinY(self.cloud_5.frame)-21, 71, 21);
[self.cloudBack addSubview:self.cloud_6];
[self.cloudBack insertSubview:self.cloud_6 belowSubview:self.cloud_5];
IFTTTFrameAnimation *cloud6frameAnimation = [IFTTTFrameAnimation animationWithView:self.cloud_6];
[cloud6frameAnimation addKeyframeForTime:firstDuration*1/2
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-30,
CGRectGetMinY(self.cloud_5.frame)-21,
71, 21)];
[cloud6frameAnimation addKeyframeForTime:firstDuration*6/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-30,
CGRectGetMinY(self.fishBowl.frame)+5,
71, 21)];
[cloud6frameAnimation addKeyframeForTime:firstDuration*7/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-30,
CGRectGetMinY(self.fishBowl.frame)-5,
71, 21)];
[cloud6frameAnimation addKeyframeForTime:firstDuration
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-30,
CGRectGetMinY(self.fishBowl.frame),
71, 21)];
[self.waterDropAnimator addAnimation:cloud6frameAnimation];
self.cloud_7 = [[UIImageView alloc]initWithImage:Image(@"animationImages/cloud_7.png")];
self.cloud_7.frame = CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-60, CGRectGetMinY(self.cloud_6.frame)-31, 71, 31);
[self.cloudBack addSubview:self.cloud_7];
[self.cloudBack insertSubview:self.cloud_7 belowSubview:self.cloud_6];
IFTTTFrameAnimation *cloud7frameAnimation = [IFTTTFrameAnimation animationWithView:self.cloud_7];
[cloud7frameAnimation addKeyframeForTime:firstDuration*1/2
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-60,
CGRectGetMinY(self.cloud_6.frame)-31,
71, 31)];
[cloud7frameAnimation addKeyframeForTime:firstDuration*6/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-60,
CGRectGetMinY(self.fishBowl.frame)-25,
71, 31)];
[cloud7frameAnimation addKeyframeForTime:firstDuration*7/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-60,
CGRectGetMinY(self.fishBowl.frame)-35,
71, 31)];
[cloud7frameAnimation addKeyframeForTime:firstDuration
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-60,
CGRectGetMinY(self.fishBowl.frame)-31,
71, 31)];
[self.waterDropAnimator addAnimation:cloud7frameAnimation];
self.cloud_8 = [[UIImageView alloc]initWithImage:Image(@"animationImages/cloud_8.png")];
self.cloud_8.frame = CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-85, CGRectGetMinY(self.cloud_7.frame)-37/2, 71, 37/2);
[self.cloudBack addSubview:self.cloud_8];
[self.cloudBack insertSubview:self.cloud_8 belowSubview:self.cloud_7];
IFTTTFrameAnimation *cloud8frameAnimation = [IFTTTFrameAnimation animationWithView:self.cloud_8];
[cloud8frameAnimation addKeyframeForTime:firstDuration*1/2
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-85,
CGRectGetMinY(self.cloud_7.frame)-37/2,
71, 37/2)];
[cloud8frameAnimation addKeyframeForTime:firstDuration*6/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-85,
CGRectGetMinY(self.fishBowl.frame)-45,
71, 37/2)];
[cloud8frameAnimation addKeyframeForTime:firstDuration*7/8
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-85,
CGRectGetMinY(self.fishBowl.frame)-55,
71, 37/2)];
[cloud8frameAnimation addKeyframeForTime:firstDuration
frame:CGRectMake(CGRectGetMaxX(self.fishBowl.frame)-85,
CGRectGetMinY(self.fishBowl.frame)-49,
71, 37/2)];
[self.waterDropAnimator addAnimation:cloud8frameAnimation];
}
#pragma mark - fish path
- (CGPathRef)fishPath {
UIBezierPath *fishPath = [UIBezierPath bezierPath];
[fishPath moveToPoint: CGPointMake(0, 0)];
[fishPath addQuadCurveToPoint: CGPointMake(-45, -55) controlPoint: CGPointMake(-22, -15)];
[fishPath addQuadCurveToPoint: CGPointMake(-30, -145) controlPoint: CGPointMake(-55, -110)];
return fishPath.CGPath;
}
- (CAShapeLayer *)fishePathLayer
{
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = self.smallFish.frame;
shapeLayer.path = [self fishPath];
shapeLayer.fillColor = nil;
shapeLayer.strokeColor = [UIColor clearColor].CGColor;
shapeLayer.lineWidth = 0;
shapeLayer.miterLimit = 0;
shapeLayer.fillRule = kCAFillRuleEvenOdd;
return shapeLayer;
}
- (CGPathRef)fishBowlPath {
UIBezierPath *fishPath = [UIBezierPath bezierPath];
[fishPath moveToPoint: CGPointMake(0, 0)];
[fishPath addQuadCurveToPoint: CGPointMake(0, 160/2) controlPoint: CGPointMake(40/2, 45/2)];
[fishPath addQuadCurveToPoint: CGPointMake(-160/2, 270/2) controlPoint: CGPointMake(-60/2,270/2)];
return fishPath.CGPath;
}
- (CAShapeLayer *)fishBowlPathLayer
{
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = self.fishBowlBlackView.frame;
shapeLayer.path = [self fishBowlPath];
shapeLayer.fillColor = nil;
shapeLayer.strokeColor = [UIColor blackColor].CGColor;
shapeLayer.lineWidth = 1;
shapeLayer.miterLimit = 1;
shapeLayer.fillRule = kCAFillRuleEvenOdd;
return shapeLayer;
}
#pragma mark - fish bowl path
#pragma mark - configure animator view
- (void)configureAnimatorView {
self.waterDropAnimator = [IFTTTAnimator new];
IFTTTFrameAnimation *frameAnimation = [IFTTTFrameAnimation animationWithView:self.waterDrop];
[frameAnimation addKeyframeForTime:0
frame:waterDropSourceRect
withEasingFunction:IFTTTEasingFunctionEaseInQuad];
[frameAnimation addKeyframeForTime:firstDuration/4
frame:waterDropDownRect
withEasingFunction:IFTTTEasingFunctionEaseOutQuad];
[self.waterDropAnimator addAnimation:frameAnimation];
IFTTTAlphaAnimation *textAlphaAnimation = [IFTTTAlphaAnimation animationWithView:self.textImageView1];
[textAlphaAnimation addKeyframeForTime:0 alpha:0.f];
[textAlphaAnimation addKeyframeForTime:firstDuration/4 alpha:0.5f];
[textAlphaAnimation addKeyframeForTime:firstDuration alpha:1.0f];
[self.waterDropAnimator addAnimation:textAlphaAnimation];
}
#pragma mark - add animator timer and gesture
- (void)addtimer {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:firstTimeInterval target:self selector:@selector(frameTimer:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop]addTimer:timer forMode:NSRunLoopCommonModes];
self.cloud_1.hidden = NO;
});
}
#pragma mark - add second stage gesture
- (void)addPanGestureInView {
self.pangesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
self.pangesture.delaysTouchesBegan = YES;
[self.backView addGestureRecognizer:self.pangesture];
}
#pragma mark - timer animation
- (void)frameTimer:(NSTimer*)timer {
timerCount = timerCount + firstTimeInterval;
if (timerCount > firstDuration) {
[timer invalidate];
timer = nil;
[self.smallFishPathLayer removeFromSuperlayer];
[self.smallFishPathView removeFromSuperview];
[self.smallFish removeFromSuperview];
self.smallFish = nil;
self.smallFish = [[UIImageView alloc]initWithImage:Image(@"animationImages/smallFish_2.png")];
[self.cloudBack addSubview:self.smallFish];
self.smallFish.frame = CGRectMake(CGRectGetMinX(self.fishBowl.frame)+20, CGRectGetMinY(self.fishBowl.frame)-61, 76/2, 96/2);
self.bigFish = [[UIImageView alloc]initWithImage:Image(@"animationImages/bigFish.png")];
self.bigFish.frame = CGRectMake(CGRectGetWidth(self.view.bounds)/2-74/2, CGRectGetMinY(self.cloud_1.frame)-342/2+74, 300/2, 342/2);
// self.bigFish.center = CGPointMake(self.view.center.x+35, self.view.center.y+25+50);
self.bigFish.alpha = 0.0f;
self.bigFish.transform = CGAffineTransformMakeScale(0.0f,0.0f);
[self.view addSubview:self.bigFish];
self.birds = [[UIImageView alloc]initWithImage:Image(@"animationImages/birds.png")];
self.birds.frame = CGRectMake(CGRectGetWidth(self.view.bounds)/2-5, CGRectGetMinY(self.water3.frame)+7, 149/2, 53/2);
birdsRect = self.birds.frame;
[self.backView addSubview:self.birds];
[self.backView insertSubview:self.birds belowSubview:self.fishBowl];
[self addPanGestureInView];
self.currentIndex = 0;
self.leftSwipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipeGestureHandler:)];
[self.leftSwipeGesture delaysTouchesBegan];
self.leftSwipeGesture.numberOfTouchesRequired = 1;
self.leftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
self.leftSwipeGesture.delegate = self;
self.leftSwipeGesture.enabled = NO;
[self.backView addGestureRecognizer:self.leftSwipeGesture];
[TPUserDefault instance].visitTime = @"0";
[TPUserDefault instance].isAttention = @"0";
[self.backView addSubview:self.pageControl];
self.pageControl.numberOfPages = 2;
self.pageControl.currentPage = self.currentIndex;
if (IS_IPHONE4) {
[self.pageControl remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view.centerX);
make.bottom.equalTo(self.view.bottom).offset(-70);
make.height.equalTo(@10);
make.width.equalTo(@140);
}];
}else if (IS_IPHONE5){
[self.pageControl remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view.centerX);
make.bottom.equalTo(self.view.bottom).offset(-100);
make.height.equalTo(@10);
make.width.equalTo(@140);
}];
}else if (rect_screen.size.height == 667){
[self.pageControl remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view.centerX);
make.bottom.equalTo(self.view.bottom).offset(-120);
make.height.equalTo(@10);
make.width.equalTo(@140);
}];
}else if (rect_screen.size.height == 736){
[self.pageControl remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view.centerX);
make.bottom.equalTo(self.view.bottom).offset(-130);
make.height.equalTo(@10);
make.width.equalTo(@140);
}];
}
return;
}
if (round(timerCount *100) == round(firstDuration/4.f * 100)) {
[self addSmallFish];
[self addWater];
[self addCloud];
}
if (round(timerCount *100) == round(firstDuration*1/2.f * 100)) {
self.fishBowlLidView.alpha = 1.0f;
}
if (round(timerCount *100) == round(firstDuration*5/8.f * 100)) {
self.bubble.alpha = 1.0f;
[self addBubble];
}
[self.waterDropAnimator animate:timerCount];
}
#pragma mark - textView
- (void)changeTextViewInPage0 {
IFTTTAlphaAnimation *alphaAnimation1 = [IFTTTAlphaAnimation animationWithView:self.textImageView1];
[alphaAnimation1 addKeyframeForTime:0 alpha:1];
[alphaAnimation1 addKeyframeForTime:swipeStandardOffset/2 alpha:0];
[self.gestureAnimator1 addAnimation:alphaAnimation1];
IFTTTAlphaAnimation *alphaAnimation2 = [IFTTTAlphaAnimation animationWithView:self.textImageView2];
[alphaAnimation2 addKeyframeForTime:swipeStandardOffset/2 alpha:0];
[alphaAnimation2 addKeyframeForTime:swipeStandardOffset alpha:1];
[self.gestureAnimator1 addAnimation:alphaAnimation2];
}
- (void)changeTextViewInPage1 {
IFTTTAlphaAnimation *alphaAnimation1 = [IFTTTAlphaAnimation animationWithView:self.textImageView2];
[alphaAnimation1 addKeyframeForTime:0 alpha:1];
[alphaAnimation1 addKeyframeForTime:0-swipeStandardOffset/2 alpha:0];
[self.gestureAnimator2 addAnimation:alphaAnimation1];
IFTTTAlphaAnimation *alphaAnimation2 = [IFTTTAlphaAnimation animationWithView:self.textImageView1];
[alphaAnimation2 addKeyframeForTime:0-swipeStandardOffset/2 alpha:0];
[alphaAnimation2 addKeyframeForTime:0-swipeStandardOffset alpha:1];
[self.gestureAnimator2 addAnimation:alphaAnimation2];
}
- (void)rotateFishBowLidInPage0 {
IFTTTRotationAnimation *rotationAnimation = [IFTTTRotationAnimation animationWithView:self.fishBowlLidView];
[rotationAnimation addKeyframeForTime:0 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:swipeStandardOffset/2 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:swipeStandardOffset rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:rotationAnimation];
IFTTTAlphaAnimation *alphaAnimation = [IFTTTAlphaAnimation animationWithView:self.fishBowlLidView];
[alphaAnimation addKeyframeForTime:0 alpha:1.0f];
[alphaAnimation addKeyframeForTime:swipeStandardOffset/6 alpha:0.0f];
[alphaAnimation addKeyframeForTime:swipeStandardOffset alpha:0.0f];
[self.gestureAnimator1 addAnimation:alphaAnimation];
IFTTTTranslationAnimation *translationAnimation = [IFTTTTranslationAnimation animationWithView:self.fishBowlLidView];
[translationAnimation addKeyframeForTime:0 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset/4 translation:CGPointMake(100, -25) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset/2 translation:CGPointMake(0, -100) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:translationAnimation];
}
- (void)rotateFishBowLidInPage1 {
IFTTTRotationAnimation *rotationAnimation = [IFTTTRotationAnimation animationWithView:self.fishBowlLidView];
[rotationAnimation addKeyframeForTime:0 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset/2 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:rotationAnimation];
IFTTTAlphaAnimation *alphaAnimation = [IFTTTAlphaAnimation animationWithView:self.fishBowlLidView];
[alphaAnimation addKeyframeForTime:0 alpha:0.0f];
[alphaAnimation addKeyframeForTime:0-swipeStandardOffset/6 alpha:0.0f];
[alphaAnimation addKeyframeForTime:0-swipeStandardOffset alpha:1.0f];
[self.gestureAnimator2 addAnimation:alphaAnimation];
IFTTTTranslationAnimation *translationAnimation = [IFTTTTranslationAnimation animationWithView:self.fishBowlLidView];
[translationAnimation addKeyframeForTime:0 translation:CGPointMake(0, -100) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:0-swipeStandardOffset/4 translation:CGPointMake(100, -25) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:0-swipeStandardOffset/2 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:translationAnimation];
}
- (void)rotateFishBowlInPage0 {
IFTTTRotationAnimation *rotationAnimation = [IFTTTRotationAnimation animationWithView:self.fishBowl];
[rotationAnimation addKeyframeForTime:0 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:swipeStandardOffset/2 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:swipeStandardOffset rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:rotationAnimation];
IFTTTTranslationAnimation *translationAnimation = [IFTTTTranslationAnimation animationWithView:self.fishBowl];
[translationAnimation addKeyframeForTime:0 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset/4 translation:CGPointMake(0, transformOffset/2) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset/2 translation:CGPointMake(0, transformOffset) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset translation:CGPointMake(0, transformOffset) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:translationAnimation];
}
- (void)rotateFishBowlInPage1 {
IFTTTRotationAnimation *rotationAnimation = [IFTTTRotationAnimation animationWithView:self.fishBowl];
[rotationAnimation addKeyframeForTime:0 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset/2 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:rotationAnimation];
IFTTTTranslationAnimation *translationAnimation = [IFTTTTranslationAnimation animationWithView:self.fishBowl];
[translationAnimation addKeyframeForTime:0 translation:CGPointMake(0, transformOffset) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:0-swipeStandardOffset/4 translation:CGPointMake(0, transformOffset/2) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:0-swipeStandardOffset/2 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:0-swipeStandardOffset translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:translationAnimation];
}
- (void)rotateLineInPage0 {
IFTTTRotationAnimation *rotationAnimation = [IFTTTRotationAnimation animationWithView:self.line_in];
[rotationAnimation addKeyframeForTime:0 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:swipeStandardOffset/4+10 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:swipeStandardOffset/2+10 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:swipeStandardOffset rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:rotationAnimation];
IFTTTTranslationAnimation *translationAnimation = [IFTTTTranslationAnimation animationWithView:self.line_in];
[translationAnimation addKeyframeForTime:0 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset/4+10 translation:CGPointMake(45/2, transformOffset/2+70/8) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset/2+10 translation:CGPointMake(45, transformOffset+70/4) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset translation:CGPointMake(45, transformOffset+70/4) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:translationAnimation];
IFTTTRotationAnimation *rotationAnimationOut = [IFTTTRotationAnimation animationWithView:self.line_out];
[rotationAnimationOut addKeyframeForTime:0 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimationOut addKeyframeForTime:swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimationOut addKeyframeForTime:swipeStandardOffset/2 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimationOut addKeyframeForTime:swipeStandardOffset rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:rotationAnimationOut];
IFTTTTranslationAnimation *translationAnimationOut = [IFTTTTranslationAnimation animationWithView:self.line_out];
[translationAnimationOut addKeyframeForTime:0 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimationOut addKeyframeForTime:swipeStandardOffset/4 translation:CGPointMake(5, transformOffset/2+25) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimationOut addKeyframeForTime:swipeStandardOffset/2 translation:CGPointMake(10, transformOffset+50) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimationOut addKeyframeForTime:swipeStandardOffset translation:CGPointMake(10, transformOffset+50) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:translationAnimationOut];
}
- (void)rotateLineInPage1 {
IFTTTRotationAnimation *rotationAnimation = [IFTTTRotationAnimation animationWithView:self.line_in];
[rotationAnimation addKeyframeForTime:0 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset/4-10 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset/2-10 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:rotationAnimation];
IFTTTTranslationAnimation *translationAnimation = [IFTTTTranslationAnimation animationWithView:self.line_in];
[translationAnimation addKeyframeForTime:0 translation:CGPointMake(45, transformOffset+70/4) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:0-swipeStandardOffset/4-10 translation:CGPointMake(45/2, transformOffset/2+70/8) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:0-swipeStandardOffset/2-10 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:0-swipeStandardOffset translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:translationAnimation];
IFTTTRotationAnimation *rotationAnimationOut = [IFTTTRotationAnimation animationWithView:self.line_out];
[rotationAnimationOut addKeyframeForTime:0 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimationOut addKeyframeForTime:0-swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimationOut addKeyframeForTime:0-swipeStandardOffset/2 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimationOut addKeyframeForTime:0-swipeStandardOffset rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:rotationAnimationOut];
IFTTTTranslationAnimation *translationAnimationOut = [IFTTTTranslationAnimation animationWithView:self.line_out];
[translationAnimationOut addKeyframeForTime:0 translation:CGPointMake(10, transformOffset+50) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimationOut addKeyframeForTime:0-swipeStandardOffset/4 translation:CGPointMake(5, transformOffset/2+25) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimationOut addKeyframeForTime:0-swipeStandardOffset/2 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimationOut addKeyframeForTime:0-swipeStandardOffset translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:translationAnimationOut];
}
- (void)rotateWaterInPage0 {
IFTTTRotationAnimation *rotationAnimation1 = [IFTTTRotationAnimation animationWithView:self.water1];
[rotationAnimation1 addKeyframeForTime:0 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset/8 rotation:-45 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset*3/8 rotation:-270 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset/2 rotation:-360 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:rotationAnimation1];
IFTTTTranslationAnimation *translationAnimation1 = [IFTTTTranslationAnimation animationWithView:self.water1];
[translationAnimation1 addKeyframeForTime:0 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation1 addKeyframeForTime:swipeStandardOffset/2 translation:CGPointMake(0, waterformOffset) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:translationAnimation1];
IFTTTAlphaAnimation *alphaAnimation1 = [IFTTTAlphaAnimation animationWithView:self.water1];
[alphaAnimation1 addKeyframeForTime:0 alpha:1];
[alphaAnimation1 addKeyframeForTime:swipeStandardOffset/4 alpha:0];
[alphaAnimation1 addKeyframeForTime:swipeStandardOffset/2 alpha:1];
[self.gestureAnimator1 addAnimation:alphaAnimation1];
IFTTTRotationAnimation *rotationAnimation2 = [IFTTTRotationAnimation animationWithView:self.water2];
[rotationAnimation2 addKeyframeForTime:0 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation2 addKeyframeForTime:swipeStandardOffset/8 rotation:-45 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation2 addKeyframeForTime:swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation2 addKeyframeForTime:swipeStandardOffset*3/8 rotation:-270 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation2 addKeyframeForTime:swipeStandardOffset/2 rotation:-360 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:rotationAnimation2];
IFTTTTranslationAnimation *translationAnimation2 = [IFTTTTranslationAnimation animationWithView:self.water2];
[translationAnimation2 addKeyframeForTime:0 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation2 addKeyframeForTime:swipeStandardOffset/2 translation:CGPointMake(0, waterformOffset) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:translationAnimation2];
IFTTTAlphaAnimation *alphaAnimation2 = [IFTTTAlphaAnimation animationWithView:self.water2];
[alphaAnimation2 addKeyframeForTime:0 alpha:1];
[alphaAnimation2 addKeyframeForTime:swipeStandardOffset/4 alpha:0];
[alphaAnimation2 addKeyframeForTime:swipeStandardOffset/2 alpha:1];
[self.gestureAnimator1 addAnimation:alphaAnimation2];
IFTTTRotationAnimation *rotationAnimation3 = [IFTTTRotationAnimation animationWithView:self.water3];
[rotationAnimation3 addKeyframeForTime:0 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation3 addKeyframeForTime:swipeStandardOffset/8 rotation:-45 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation3 addKeyframeForTime:swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation3 addKeyframeForTime:swipeStandardOffset*3/8 rotation:-270 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation3 addKeyframeForTime:swipeStandardOffset/2 rotation:-360 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:rotationAnimation3];
IFTTTTranslationAnimation *translationAnimation3 = [IFTTTTranslationAnimation animationWithView:self.water3];
[translationAnimation3 addKeyframeForTime:0 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation3 addKeyframeForTime:swipeStandardOffset/2 translation:CGPointMake(0, waterformOffset) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:translationAnimation3];
IFTTTAlphaAnimation *alphaAnimation3 = [IFTTTAlphaAnimation animationWithView:self.water3];
[alphaAnimation3 addKeyframeForTime:0 alpha:1];
[alphaAnimation3 addKeyframeForTime:swipeStandardOffset/4 alpha:0];
[alphaAnimation3 addKeyframeForTime:swipeStandardOffset/2 alpha:1];
[self.gestureAnimator1 addAnimation:alphaAnimation3];
}
- (void)rotateWaterInPage1 {
IFTTTRotationAnimation *rotationAnimation1 = [IFTTTRotationAnimation animationWithView:self.water1];
[rotationAnimation1 addKeyframeForTime:0 rotation:-360 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:0-swipeStandardOffset/8 rotation:-270 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:0-swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:0-swipeStandardOffset*3/8 rotation:-45 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:0-swipeStandardOffset/2 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:rotationAnimation1];
IFTTTTranslationAnimation *translationAnimation1 = [IFTTTTranslationAnimation animationWithView:self.water1];
[translationAnimation1 addKeyframeForTime:0 translation:CGPointMake(0, waterformOffset) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation1 addKeyframeForTime:0-swipeStandardOffset/2 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:translationAnimation1];
IFTTTAlphaAnimation *alphaAnimation1 = [IFTTTAlphaAnimation animationWithView:self.water1];
[alphaAnimation1 addKeyframeForTime:0 alpha:1];
[alphaAnimation1 addKeyframeForTime:0-swipeStandardOffset/4 alpha:0];
[alphaAnimation1 addKeyframeForTime:0-swipeStandardOffset/2 alpha:1];
[self.gestureAnimator2 addAnimation:alphaAnimation1];
IFTTTRotationAnimation *rotationAnimation2 = [IFTTTRotationAnimation animationWithView:self.water2];
[rotationAnimation2 addKeyframeForTime:0 rotation:-360 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation2 addKeyframeForTime:0-swipeStandardOffset/8 rotation:-270 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation2 addKeyframeForTime:0-swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation2 addKeyframeForTime:0-swipeStandardOffset*3/8 rotation:-45 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation2 addKeyframeForTime:0-swipeStandardOffset/2 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:rotationAnimation2];
IFTTTTranslationAnimation *translationAnimation2 = [IFTTTTranslationAnimation animationWithView:self.water2];
[translationAnimation2 addKeyframeForTime:0 translation:CGPointMake(0, waterformOffset) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation2 addKeyframeForTime:0-swipeStandardOffset/2 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:translationAnimation2];
IFTTTAlphaAnimation *alphaAnimation2 = [IFTTTAlphaAnimation animationWithView:self.water2];
[alphaAnimation2 addKeyframeForTime:0 alpha:1];
[alphaAnimation2 addKeyframeForTime:0-swipeStandardOffset/4 alpha:0];
[alphaAnimation2 addKeyframeForTime:0-swipeStandardOffset/2 alpha:1];
[self.gestureAnimator2 addAnimation:alphaAnimation2];
IFTTTRotationAnimation *rotationAnimation3 = [IFTTTRotationAnimation animationWithView:self.water3];
[rotationAnimation3 addKeyframeForTime:0 rotation:-360 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation3 addKeyframeForTime:0-swipeStandardOffset/8 rotation:-270 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation3 addKeyframeForTime:0-swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation3 addKeyframeForTime:0-swipeStandardOffset*3/8 rotation:-45 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation3 addKeyframeForTime:0-swipeStandardOffset/2 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:rotationAnimation3];
IFTTTTranslationAnimation *translationAnimation3 = [IFTTTTranslationAnimation animationWithView:self.water3];
[translationAnimation3 addKeyframeForTime:0 translation:CGPointMake(0, waterformOffset) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation3 addKeyframeForTime:0-swipeStandardOffset/2 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:translationAnimation3];
IFTTTAlphaAnimation *alphaAnimation3 = [IFTTTAlphaAnimation animationWithView:self.water3];
[alphaAnimation3 addKeyframeForTime:0 alpha:1];
[alphaAnimation3 addKeyframeForTime:0-swipeStandardOffset/4 alpha:0];
[alphaAnimation3 addKeyframeForTime:0-swipeStandardOffset/2 alpha:1];
[self.gestureAnimator2 addAnimation:alphaAnimation3];
}
- (void)rotateCloudBackInPage0 {
IFTTTRotationAnimation *rotationAnimation1 = [IFTTTRotationAnimation animationWithView:self.cloudBack];
[rotationAnimation1 addKeyframeForTime:0 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset/25 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset/4 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset/2 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:rotationAnimation1];
IFTTTAlphaAnimation *alphaAnimation = [IFTTTAlphaAnimation animationWithView:self.smallFish];
[alphaAnimation addKeyframeForTime:0 alpha:1.0f];
[alphaAnimation addKeyframeForTime:swipeStandardOffset/8 alpha:1.0f];
[alphaAnimation addKeyframeForTime:swipeStandardOffset/3 alpha:0.5f];
[alphaAnimation addKeyframeForTime:swipeStandardOffset*3/7 alpha:0.0f];
[self.gestureAnimator1 addAnimation:alphaAnimation];
}
- (void)rotateCloudBackInPage1 {
IFTTTRotationAnimation *rotationAnimation1 = [IFTTTRotationAnimation animationWithView:self.cloudBack];
[rotationAnimation1 addKeyframeForTime:0 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:0-swipeStandardOffset/8 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:0-swipeStandardOffset/3 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:0-swipeStandardOffset*3/7 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:0-swipeStandardOffset rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:rotationAnimation1];
IFTTTAlphaAnimation *alphaAnimation = [IFTTTAlphaAnimation animationWithView:self.smallFish];
[alphaAnimation addKeyframeForTime:0 alpha:0.0f];
[alphaAnimation addKeyframeForTime:0-swipeStandardOffset/8 alpha:0.0f];
[alphaAnimation addKeyframeForTime:0-swipeStandardOffset/3 alpha:0.8f];
[alphaAnimation addKeyframeForTime:0-swipeStandardOffset*3/7 alpha:1.0f];
[self.gestureAnimator2 addAnimation:alphaAnimation];
}
- (void)rotateCloud_1InPage0 {
IFTTTRotationAnimation *rotationAnimation1 = [IFTTTRotationAnimation animationWithView:self.cloud_1];
[rotationAnimation1 addKeyframeForTime:0 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset/4 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset/3 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset*3/7 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation1 addKeyframeForTime:swipeStandardOffset rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:rotationAnimation1];
}
- (void)rotateCloud_1InPage1 {
IFTTTRotationAnimation *rotationAnimation = [IFTTTRotationAnimation animationWithView:self.cloud_1];
[rotationAnimation addKeyframeForTime:0 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset/4 rotation:-180 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset/3 rotation:-90 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset*3/7 rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[rotationAnimation addKeyframeForTime:0-swipeStandardOffset rotation:0 withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:rotationAnimation];
}
- (void)animationOfBigFishInPage0 {
self.bigFish.alpha = 1.0f;
IFTTTScaleAnimation *scaleAnimation = [IFTTTScaleAnimation animationWithView:self.bigFish];
[scaleAnimation addKeyframeForTime:0 scale:0.001];
[scaleAnimation addKeyframeForTime:swipeStandardOffset/4 scale:0.001];
[scaleAnimation addKeyframeForTime:swipeStandardOffset*3/8 scale:0.001];
[scaleAnimation addKeyframeForTime:swipeStandardOffset*2/4 scale:1.0];
[self.gestureAnimator1 addAnimation:scaleAnimation];
IFTTTTranslationAnimation *translationAnimation = [IFTTTTranslationAnimation animationWithView:self.bigFish];
[translationAnimation addKeyframeForTime:0 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset*3/8 translation:CGPointMake(0, 10) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:swipeStandardOffset/2 translation:CGPointMake(-10, -30) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator1 addAnimation:translationAnimation];
IFTTTRotationAnimation *rotateAnimation = [IFTTTRotationAnimation animationWithView:self.bigFish];
[rotateAnimation addKeyframeForTime:0 rotation:0];
[rotateAnimation addKeyframeForTime:swipeStandardOffset*3/8 rotation:0];
[rotateAnimation addKeyframeForTime:swipeStandardOffset*3/4 rotation:-25];
[self.gestureAnimator1 addAnimation:rotateAnimation];
}
- (void)animationOfBigFishInPage1 {
IFTTTScaleAnimation *scaleAnimation = [IFTTTScaleAnimation animationWithView:self.bigFish];
[scaleAnimation addKeyframeForTime:0 scale:1];
[scaleAnimation addKeyframeForTime:0-swipeStandardOffset/4 scale:0.001];
[scaleAnimation addKeyframeForTime:0-swipeStandardOffset*3/8 scale:0.001];
[self.gestureAnimator2 addAnimation:scaleAnimation];
IFTTTTranslationAnimation *translationAnimation = [IFTTTTranslationAnimation animationWithView:self.bigFish];
[translationAnimation addKeyframeForTime:0 translation:CGPointMake(-10, -30) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[translationAnimation addKeyframeForTime:0-swipeStandardOffset/4 translation:CGPointMake(0, 0) withEasingFunction:IFTTTEasingFunctionEaseInOutQuad];
[self.gestureAnimator2 addAnimation:translationAnimation];
IFTTTRotationAnimation *rotateAnimation = [IFTTTRotationAnimation animationWithView:self.bigFish];
[rotateAnimation addKeyframeForTime:0 rotation:-25];
[rotateAnimation addKeyframeForTime:0-swipeStandardOffset/4 rotation:0];
[self.gestureAnimator2 addAnimation:rotateAnimation];
}
- (void)animationOfCloudInPage0 {
NSArray *cloudList = [NSArray arrayWithObjects:self.cloud_2,self.cloud_3,self.cloud_4,self.cloud_5,self.cloud_6,self.cloud_7,self.cloud_8, nil];
[cloudList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
UIView *view = obj;
CGRect rect = view.frame;
IFTTTFrameAnimation *frameAnimation = [IFTTTFrameAnimation animationWithView:view];
[frameAnimation addKeyframeForTime:0 frame:rect];
if (idx%2 == 0) {
rect.origin.x = rect.origin.x + 20;
}else {
rect.origin.x = rect.origin.x - 20;
}
[frameAnimation addKeyframeForTime:swipeStandardOffset/25 frame:rect];
[frameAnimation addKeyframeForTime:swipeStandardOffset/2 frame:rect];
if (idx%2 == 0) {
rect.origin.x = rect.origin.x - 30;
}else {
rect.origin.x = rect.origin.x + 30;
}
[frameAnimation addKeyframeForTime:swipeStandardOffset*3/4 frame:rect];
[self.gestureAnimator1 addAnimation:frameAnimation];
}];
}
- (void)animationOfCloudInPage1 {
NSArray *cloudList = [NSArray arrayWithObjects:self.cloud_2,self.cloud_3,self.cloud_4,self.cloud_5,self.cloud_6,self.cloud_7,self.cloud_8, nil];
[cloudList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
UIView *view = obj;
CGRect rect = view.frame;
IFTTTFrameAnimation *frameAnimation = [IFTTTFrameAnimation animationWithView:view];
[frameAnimation addKeyframeForTime:0 frame:rect];
if (idx%2 == 0) {
rect.origin.x = rect.origin.x - 20;
}else {
rect.origin.x = rect.origin.x + 20;
}
[frameAnimation addKeyframeForTime:0-swipeStandardOffset/25 frame:rect];
[frameAnimation addKeyframeForTime:0-swipeStandardOffset/2 frame:rect];
if (idx%2 == 0) {
rect.origin.x = rect.origin.x + 30;
}else {
rect.origin.x = rect.origin.x - 30;
}
[frameAnimation addKeyframeForTime:0-swipeStandardOffset*3/4 frame:rect];
[self.gestureAnimator2 addAnimation:frameAnimation];
}];
}
- (void)animationOfBirdsInPage0 {
IFTTTAlphaAnimation *scaleAnimation = [IFTTTAlphaAnimation animationWithView:self.birds];
[scaleAnimation addKeyframeForTime:0 alpha:0.0f];
[scaleAnimation addKeyframeForTime:swipeStandardOffset/2 alpha:0];
[scaleAnimation addKeyframeForTime:swipeStandardOffset*3/4 alpha:1];
[self.gestureAnimator1 addAnimation:scaleAnimation];
CGRect rect = birdsRect;
IFTTTFrameAnimation *frameAnimation = [IFTTTFrameAnimation animationWithView:self.birds];
[frameAnimation addKeyframeForTime:0 frame:birdsRect];
[frameAnimation addKeyframeForTime:swipeStandardOffset/2 frame:rect];
rect.origin.y = rect.origin.y - 30;
rect.origin.x = rect.origin.x - 5;
[frameAnimation addKeyframeForTime:swipeStandardOffset*3/4 frame:rect];
[self.gestureAnimator1 addAnimation:frameAnimation];
}
- (void)animationOfBirdsInPage1 {
IFTTTAlphaAnimation *scaleAnimation = [IFTTTAlphaAnimation animationWithView:self.birds];
[scaleAnimation addKeyframeForTime:0 alpha:1];
[scaleAnimation addKeyframeForTime:0-swipeStandardOffset/25 alpha:0.f];
[self.gestureAnimator2 addAnimation:scaleAnimation];
CGRect rect = self.birds.frame;
IFTTTFrameAnimation *frameAnimation = [IFTTTFrameAnimation animationWithView:self.birds];
[frameAnimation addKeyframeForTime:0 frame:rect];
[frameAnimation addKeyframeForTime:0-swipeStandardOffset/25 frame:birdsRect];
[self.gestureAnimator2 addAnimation:frameAnimation];
}
#pragma mark - pan animation
- (void)pan:(UIPanGestureRecognizer*)pan {
CGPoint touchPoint = [pan locationInView:self.backView];
if (pan.state == UIGestureRecognizerStateBegan) {
startTouch = touchPoint;
}else if (pan.state == UIGestureRecognizerStateEnded) {
// NSLog(@"endddddddd");
if (touchPoint.x - startTouch.x <0) {
if (self.currentIndex == 1) {
return;
}
if (touchPoint.x - startTouch.x < swipeStandardOffset/4) {
[UIView animateWithDuration:animationDuration animations:^{
[self.gestureAnimator1 animate:swipeStandardOffset];
} completion:^(BOOL finished) {
self.currentIndex = 1;
}];
}else {
[UIView animateWithDuration:animationDuration animations:^{
[self.gestureAnimator1 animate:0];
} completion:^(BOOL finished) {
}];
}
}else {
if (self.currentIndex == 0) {
return;
}
if (touchPoint.x - startTouch.x < 0-swipeStandardOffset/4) {
[UIView animateWithDuration:animationDuration animations:^{
[self.gestureAnimator2 animate:0];
} completion:^(BOOL finished) {
}];
}else {
[UIView animateWithDuration:animationDuration animations:^{
[self.gestureAnimator2 animate:0-swipeStandardOffset];
} completion:^(BOOL finished) {
self.currentIndex = 0;
}];
}
}
return;
}else if (pan.state == UIGestureRecognizerStateCancelled) {
if (touchPoint.x - startTouch.x <0) {
if (self.currentIndex == 1) {
return;
}
if (touchPoint.x - startTouch.x < swipeStandardOffset/4) {
[UIView animateWithDuration:animationDuration animations:^{
[self.gestureAnimator1 animate:swipeStandardOffset];
} completion:^(BOOL finished) {
self.currentIndex = 1;
}];
}else {
[UIView animateWithDuration:animationDuration animations:^{
[self.gestureAnimator1 animate:0];
} completion:^(BOOL finished) {
}];
}
}else {
if (self.currentIndex == 0) {
return;
}
if (touchPoint.x - startTouch.x < 0-swipeStandardOffset/4) {
[UIView animateWithDuration:animationDuration animations:^{
[self.gestureAnimator2 animate:0];
} completion:^(BOOL finished) {
}];
}else {
[UIView animateWithDuration:animationDuration animations:^{
[self.gestureAnimator2 animate:0-swipeStandardOffset];
} completion:^(BOOL finished) {
self.currentIndex = 0;
}];
}
}
return;
}
[self moveWithOffset:touchPoint.x-startTouch.x pan:pan];
}
- (void)moveWithOffset:(CGFloat)offset pan:(UIPanGestureRecognizer*)gesture {
// NSLog(@"%f %f",offset,swipeStandardOffset);
if (self.currentIndex == 0) {
if (offset > 0) return;
}
if (self.currentIndex == 1) {
if (offset < 0) return;
}
if (self.currentIndex == 0) {
[self.gestureAnimator1 animate:offset];
}else {
[self.gestureAnimator2 animate:offset];
}
[gesture setTranslation:CGPointMake(0, 0) inView:self.backView];
}
#pragma mark - set pageIndex
- (void)setCurrentIndex:(NSInteger)index {
_currentIndex = index;
if (index == 0) {
self.leftSwipeGesture.enabled = NO;
self.pageControl.currentPage = 0;
[self.gestureAnimator1 removeAllAnimations];
[self.gestureAnimator2 removeAllAnimations];
if (!self.gestureAnimator1) {
self.gestureAnimator1 = [IFTTTAnimator new];
}
[self changeTextViewInPage0];
[self rotateFishBowlInPage0];
[self rotateFishBowLidInPage0];
[self rotateLineInPage0];
[self rotateWaterInPage0];
[self rotateCloudBackInPage0];
[self rotateCloud_1InPage0];
[self animationOfBigFishInPage0];
[self animationOfCloudInPage0];
[self animationOfBirdsInPage0];
}else {
self.leftSwipeGesture.enabled = YES;
self.pageControl.currentPage = 1;
[self.gestureAnimator1 removeAllAnimations];
[self.gestureAnimator2 removeAllAnimations];
if (!self.gestureAnimator2) {
self.gestureAnimator2 = [IFTTTAnimator new];
}
[self changeTextViewInPage1];
[self rotateFishBowlInPage1];
[self rotateFishBowLidInPage1];
[self rotateLineInPage1];
[self rotateWaterInPage1];
[self rotateCloudBackInPage1];
[self rotateCloud_1InPage1];
[self animationOfBigFishInPage1];
[self animationOfCloudInPage1];
[self animationOfBirdsInPage1];
}
}
#pragma mark - tools
- (UIColor *)colorWithRGBHex:(UInt32)hex {
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r / 255.0f
green:g / 255.0f
blue:b / 255.0f
alpha:1.0f];
}
// Returns a UIColor by scanning the string for a hex number and passing that to +[UIColor colorWithRGBHex:]
// Skips any leading whitespace and ignores any trailing characters
- (UIColor *)colorWithHexString:(NSString *)stringToConvert {
NSScanner *scanner = [NSScanner scannerWithString:stringToConvert];
unsigned hexNum;
if (![scanner scanHexInt:&hexNum]) return nil;
return [self colorWithRGBHex:hexNum];
}
- (void)leftSwipeGestureHandler:(id)sender {
if ([self.delegate respondsToSelector:@selector(goOutOperateNavigateion:)]) {
[self.delegate goOutOperateNavigateion:self.userInfo];
}
}
- (StyledPageControl *)pageControl {
if (!_pageControl) {
_pageControl = [[StyledPageControl alloc] initWithFrame:CGRectZero];
_pageControl.pageControlStyle = PageControlStyleThumb;
_pageControl.userInteractionEnabled = NO;
_pageControl.hidesForSinglePage = YES;
_pageControl.selectedThumbImage = Image(@"welcome/welcome_gray.png");
_pageControl.thumbImage = Image(@"welcome/welcome_white.png");
_pageControl.strokeWidth = 5;
_pageControl.gapWidth = 10;
_pageControl.diameter = 13;
_pageControl.backgroundColor = [UIColor clearColor];
}
return _pageControl;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
|