iOS動畫30案例

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event

{

//圖片向下消失

//? ? [self animationRevealFromBottom:self.iconView];

//圖片向上消失

//? ? [self? animationRevealFromTop:self.iconView];

//圖片向右消失

//? ? [self animationRevealFromLeft:self.iconView];

//圖片向左消失

//? ? [self animationRevealFromRight:self.iconView];

//圖片想上翻頁

//? ? [self animationCurlUp:self.iconView];

//圖片想下翻頁

//? ? [self animationCurlDown:self.iconView];

//圖片向上推動

//? ? [self animationPushUp:self.iconView];

//圖片向下推動

//? ? [self animationPushDown:self.iconView];

//圖片向左推動

//? ? [self animationPushLeft:self.iconView];

//圖片向右推動

//? ? [self animationPushRight:self.iconView];

//圖片從下往上推出? 帶有動畫時間

//? ? [self animationMoveUp:self.iconView duration:2.0];

//圖片從上往下推出? 帶有動畫時間

//? ? [self animationMoveDown:self.iconView duration:2.0];

//圖片從左往右推出

//? ? [self animationMoveLeft:self.iconView];

//圖片從右往左推出

//? ? [self animationMoveRight:self.iconView];

//圖片旋轉變小 又變大

//? ? [self animationRotateAndScaleEffects:self.iconView];

//圖片旋轉變小 旋轉變大

//? ? [self animationRotateAndScaleDownUp:self.iconView];

//圖片翻轉(從上往下)

//? ? [self animationFlipFromTop:self.iconView];

//圖片翻轉(從下往上)

//? ? [self animationFlipFromBottom:self.iconView];

//立體翻轉(從左往右)

//? ? [self animationCubeFromLeft:self.iconView];

//立體翻轉(從右往左)

//? ? [self animationCubeFromRight:self.iconView];

//立體翻轉(從上往下)

//? ? [self animationCubeFromTop:self.iconView];

//立體翻轉(從下往上)

//? ? [self animationCubeFromBottom:self.iconView];

//往左上角飛出

//? ? [self animationSuckEffect:self.iconView];

//抖動

//? ? [self animationRippleEffect:self.iconView];

//相機打開的動畫

//? ? [self animationCameraOpen:self.iconView];

//相機關閉的動畫

//? ? [self animationCameraClose:self.iconView];

//放大彈跳? 移除

//? ? [self dapWithView:self.iconView];

//上下彈跳

//? ? [self animationShootOut:self.iconView];

//上下減速彈跳

shakerAnimation(self.iconView,2,200.0);

}





- (void)animationCameraClose:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"cameraIrisHollowClose"];

[animation setSubtype:@"fromRight"];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationCameraOpen:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"cameraIrisHollowOpen"];

[animation setSubtype:@"fromRight"];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationRippleEffect:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"rippleEffect"];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationSuckEffect:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"suckEffect"];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationCubeFromTop:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"cube"];

[animation setSubtype:@"fromTop"];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationCubeFromBottom:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"cube"];

[animation setSubtype:@"fromBottom"];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationCubeFromRight:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"cube"];

[animation setSubtype:@"fromRight"];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationCubeFromLeft:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"cube"];

[animation setSubtype:@"fromLeft"];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationFlipFromBottom:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"oglFlip"];

[animation setSubtype:@"fromBottom"];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationFlipFromTop:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:@"oglFlip"];

[animation setSubtype:@"fromTop"];

[view.layer addAnimation:animation forKey:nil];

}

/** CABasicAnimation

*

*? @see https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/CoreAnimation_guide/Articles/KVCAdditions.html

*

*? @brief? ? ? ? ? ? ? ? ? ? ? 便利構造函數 animationWithKeyPath: KeyPath需要一個字符串類型的參數,實際上是一個

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 鍵-值編碼協議的擴展,參數必須是CALayer的某一項屬性,你的代碼會對應的去改變該屬性的效果

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 具體可以填寫什么請參考上面的URL,切勿亂填!

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 例如這里填寫的是 @"transform.rotation.z" 意思就是圍繞z軸旋轉,旋轉的單位是弧度.

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 這個動畫的效果是把view旋轉到最小,再旋轉回來.

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 你也可以填寫@"opacity" 去修改透明度...以此類推.修改layer的屬性,可以用這個類.

*

*? @param toValue? ? ? ? ? ? ? 動畫結束的值.CABasicAnimation自己只有三個屬性(都很重要)(其他屬性是繼承來的),分別為:

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? fromValue(開始值), toValue(結束值), byValue(偏移值),

!? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 這三個屬性最多只能同時設置兩個;

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 他們之間的關系如下:

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 如果同時設置了fromValue和toValue,那么動畫就會從fromValue過渡到toValue;

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 如果同時設置了fromValue和byValue,那么動畫就會從fromValue過渡到fromValue + byValue;

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 如果同時設置了byValue? 和toValue,那么動畫就會從toValue - byValue過渡到toValue;

*

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 如果只設置了fromValue,那么動畫就會從fromValue過渡到當前的value;

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 如果只設置了toValue? ,那么動畫就會從當前的value過渡到toValue;

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 如果只設置了byValue? ,那么動畫就會從從當前的value過渡到當前value + byValue.

*

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 可以這么理解,當你設置了三個中的一個或多個,系統就會根據以上規則使用插值算法計算出一個時間差并

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 同時開啟一個Timer.Timer的間隔也就是這個時間差,通過這個Timer去不停地刷新keyPath的值.

!? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 而實際上,keyPath的值(layer的屬性)在動畫運行這一過程中,是沒有任何變化的,它只是調用了GPU去

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 完成這些顯示效果而已.

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 在這個動畫里,是設置了要旋轉到的弧度,根據以上規則,動畫將會從它當前的弧度專旋轉到我設置的弧度.

*

*? @param duration? ? ? ? ? ? 動畫持續時間

*

*? @param timingFunction? ? ? 動畫起點和終點之間的插值計算,也就是說它決定了動畫運行的節奏,是快還是慢,還是先快后慢...

*/

/** CAAnimationGroup

*

*? @brief? ? ? ? ? ? ? ? ? ? ? 顧名思義,這是一個動畫組,它允許多個動畫組合在一起并行顯示.比如這里設置了兩個動畫,

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 把他們加在動畫組里,一起顯示.例如你有幾個動畫,在動畫執行的過程中需要同時修改動畫的某些屬性,

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 這時候就可以使用CAAnimationGroup.

*

*? @param duration? ? ? ? ? ? 動畫持續時間,值得一提的是,如果添加到group里的子動畫不設置此屬性,group里的duration會統一

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 設置動畫(包括子動畫)的duration屬性;但是如果子動畫設置了duration屬性,那么group的duration屬性

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 的值不應該小于每個子動畫中duration屬性的值,否則會造成子動畫顯示不全就停止了動畫.

*

*? @param autoreverses? ? ? ? 動畫完成后自動重新開始,默認為NO.

*

*? @param repeatCount? ? ? ? ? 動畫重復次數,默認為0.

*

*? @param animations? ? ? ? ? 動畫組(數組類型),把需要同時運行的動畫加到這個數組里.

*

*? @note? addAnimation:forKey? 這個方法的forKey參數是一個字符串,這個字符串可以隨意設置.

*

*? @note? ? ? ? ? ? ? ? ? ? ? 如果你需要在動畫group執行結束后保存動畫效果的話,設置 fillMode 屬性,并且把

*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? removedOnCompletion 設置為NO;

*/

- (void)animationRotateAndScaleDownUp:(UIView *)view

{

CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 2];

rotationAnimation.duration = 0.35f;

rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];

scaleAnimation.duration = 0.35f;

scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

CAAnimationGroup *animationGroup = [CAAnimationGroup animation];

animationGroup.duration = 0.35f;

animationGroup.autoreverses = YES;

animationGroup.repeatCount = 1;

animationGroup.animations =[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, nil];

[view.layer addAnimation:animationGroup forKey:@"animationGroup"];

}

- (void)animationRotateAndScaleEffects:(UIView *)view

{

[UIView animateWithDuration:0.35f animations:^

{

/**

*? @see? ? ? http://donbe.blog.163.com/blog/static/138048021201061054243442/

*

*? @param? ? transform? 形變屬性(結構體),可以利用這個屬性去對view做一些翻轉或者縮放.詳解請猛戳↑URL.

*

*? @method? ? valueWithCATransform3D: 此方法需要一個CATransform3D的結構體.一些非詳細的講解可以看下面的URL

*

*? @see? ? ? http://blog.csdn.net/liubo0_0/article/details/7452166

*

*/

view.transform = CGAffineTransformMakeScale(0.001, 0.001);

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];

// 向右旋轉45°縮小到最小,然后再從小到大推出.

animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.70, 0.40, 0.80)];

/**

*? ? 其他效果:

*? ? 從底部向上收縮一半后彈出

*? ? animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0)];

*

*? ? 從底部向上完全收縮后彈出

*? ? animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1.0, 0.0, 0.0)];

*

*? ? 左旋轉45°縮小到最小,然后再從小到大推出.

*? ? animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.50, -0.50, 0.50)];

*

*? ? 旋轉180°縮小到最小,然后再從小到大推出.

*? ? animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.1, 0.2, 0.2)];

*/

animation.duration = 0.45;

animation.repeatCount = 1;

[view.layer addAnimation:animation forKey:nil];

}

completion:^(BOOL finished)

{

[UIView animateWithDuration:0.35f animations:^

{

view.transform = CGAffineTransformMakeScale(1.0, 1.0);

}];

}];

}

- (void)animationMoveLeft:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:kCATransitionMoveIn];

[animation setSubtype:kCATransitionFromLeft];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationMoveRight:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:kCATransitionMoveIn];

[animation setSubtype:kCATransitionFromRight];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationMoveDown:(UIView *)view duration:(CFTimeInterval)duration

{

CATransition *transition = [CATransition animation];

transition.duration =0.4;

transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

transition.type = kCATransitionReveal;

transition.subtype = kCATransitionFromBottom;

[view.layer addAnimation:transition forKey:nil];

}

- (void)animationMoveUp:(UIView *)view duration:(CFTimeInterval)duration

{

CATransition *animation = [CATransition animation];

[animation setDuration:duration];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[animation setType:kCATransitionMoveIn];

[animation setSubtype:kCATransitionFromTop];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationPushLeft:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:kCATransitionPush];

[animation setSubtype:kCATransitionFromLeft];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationPushRight:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:kCATransitionPush];

[animation setSubtype:kCATransitionFromRight];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationPushDown:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:kCATransitionPush];

[animation setSubtype:kCATransitionFromBottom];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationPushUp:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[animation setType:kCATransitionPush];

[animation setSubtype:kCATransitionFromTop];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationCurlDown:(UIView *)view

{

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

[UIView setAnimationDuration:0.35f];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:view cache:NO];

[UIView commitAnimations];

}

- (void)animationCurlUp:(UIView *)view

{

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

[UIView setAnimationDuration:0.35f];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:NO];

[UIView commitAnimations];

}

- (void)animationRevealFromRight:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setType:kCATransitionReveal];

[animation setSubtype:kCATransitionFromRight];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationRevealFromLeft:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setType:kCATransitionReveal];

[animation setSubtype:kCATransitionFromLeft];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationRevealFromBottom:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setType:kCATransitionReveal];

[animation setSubtype:kCATransitionFromBottom];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

[view.layer addAnimation:animation forKey:nil];

}

- (void)animationRevealFromTop:(UIView *)view

{

CATransition *animation = [CATransition animation];

[animation setDuration:0.35f];

[animation setType:kCATransitionReveal];

[animation setSubtype:kCATransitionFromTop];

[animation setFillMode:kCAFillModeForwards];

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];

[view.layer addAnimation:animation forKey:nil];

}

- (void)dapWithView:(UIView *)animateImageView

{

[UIView animateWithDuration:0.6f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^(void){

animateImageView.frame = CGRectMake(0, 0, 320, 460);

} completion:^(BOOL finished){

[UIView animateWithDuration:0.2f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void){

animateImageView.frame = CGRectMake(0, -60, 320, 460);? //彈起

} completion:^(BOOL finished){

[UIView animateWithDuration:0.15f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^(void){

animateImageView.frame = CGRectMake(0, 0, 320, 460);

} completion:^(BOOL finished){

[UIView animateWithDuration:0.05f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void){

animateImageView.frame = CGRectMake(0, -20, 320, 460); //彈起

} completion:^(BOOL finished){

[UIView animateWithDuration:0.1f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^(void){

animateImageView.frame = CGRectMake(0, 0, 320, 460);

} completion:^(BOOL finished){

[UIView animateWithDuration:0.1f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void){

animateImageView.frame = CGRectMake(0, -4, 320, 460);? ? //彈起

} completion:^(BOOL finished){

[UIView animateWithDuration:0.1f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^(void){

animateImageView.frame = CGRectMake(0, 0, 320, 460);

} completion:^(BOOL finished){

[UIView animateWithDuration:0.3f delay:0.5f options:UIViewAnimationOptionCurveEaseIn animations:^(void){

animateImageView.frame = CGRectMake(0, -460, 320, 460);

} completion:^(BOOL finished){

[animateImageView removeFromSuperview];

[animateImageView.layer removeFromSuperlayer];

}];

}];

}];

}];

}];

}];

}];

}];

}

- (void)animationShootOut:(UIView *)animationView{

CGRect frame = animationView.frame;

[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^(void){

} completion:^(BOOL finished){

[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void){

//彈起

animationView.frame = CGRectMake(frame.origin.x, frame.origin.y-20, frame.size.width, frame.size.height);

} completion:^(BOOL finished){

[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseIn animations:^(void){

//下降

animationView.frame = frame;

} completion:^(BOOL finished){

[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void){

//彈起

animationView.frame = CGRectMake(frame.origin.x, frame.origin.y-10, frame.size.width, frame.size.height);

} completion:^(BOOL finished){

//下降

[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void){

animationView.frame = frame;

} completion:^(BOOL finished){

}];

}];

}];

}];

}];

}

void shakerAnimation (UIView *view ,NSTimeInterval duration,float height){

CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];

CGFloat currentTx = view.transform.ty;

animation.duration = duration;

animation.values = @[@(currentTx), @(currentTx + height), @(currentTx-height/3*2), @(currentTx + height/3*2), @(currentTx -height/3), @(currentTx + height/3), @(currentTx)];

animation.keyTimes = @[ @(0), @(0.225), @(0.425), @(0.6), @(0.75), @(0.875), @(1) ];

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[view.layer addAnimation:animation forKey:@"kViewShakerAnimationKey"];

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容