頭文件記得導入#import <QuartzCore/QuartzCore.h>,及加入framework動畫
+(void)exChangeOut:(UIView *)changeOutView dur:(CFTimeInterval)dur{ CAKeyframeAnimation * animation; animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; animation.duration = dur; //animation.delegate = self; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; NSMutableArray *values = [NSMutableArray array]; [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]]; [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]]; [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]]; [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]]; animation.values = values; animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"]; [changeOutView.layer addAnimation:animation forKey:nil]; }
其中changeOutView 即爲要實現動畫的那個view,dur即爲動畫的時間,調用的時候傳入這2個參數便可;spa