1:UIViewAnimationOptions
参考:http://blog.csdn.net/namehzf/article/details/7650416
typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {
UIViewAnimationOptionLayoutSubviews = 1 << 0,
UIViewAnimationOptionAllowUserInteraction = 1 << 1, // 允许视图在播放动画的时候 依旧触发事件
UIViewAnimationOptionBeginFromCurrentState = 1 << 2, // 从当前状态开始动画
UIViewAnimationOptionRepeat = 1 << 3, // 重复执行动画
UIViewAnimationOptionAutoreverse = 1 << 4, // 执行动画回路
UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, // ignore nested duration
UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, // ignore nested curve
UIViewAnimationOptionAllowAnimatedContent = 1 << 7, // animate contents (applies to transitions only)
UIViewAnimationOptionShowHideTransitionViews = 1 << 8, // flip to/from hidden state instead of adding/removing
UIViewAnimationOptionCurveEaseInOut = 0 << 16, // 由慢到快
UIViewAnimationOptionCurveEaseIn = 1 << 16, // 由慢到飞快
UIViewAnimationOptionCurveEaseOut = 2 << 16, // 由快到慢
UIViewAnimationOptionCurveLinear = 3 << 16, // 匀速展示动画
UIViewAnimationOptionTransitionNone = 0 << 20, // default
UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20,
UIViewAnimationOptionTransitionFlipFromRight = 2 << 20,
UIViewAnimationOptionTransitionCurlUp = 3 << 20,
UIViewAnimationOptionTransitionCurlDown = 4 << 20,
UIViewAnimationOptionTransitionCrossDissolve = 5 << 20,
UIViewAnimationOptionTransitionFlipFromTop = 6 << 20,
UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20,
} NS_ENUM_AVAILABLE_IOS(4_0);
1:View改变大小和位置
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelegate:self];
self.frame =CGRectMake(0,self.frame.size.height-44,self.frame.size.width,44);
[UIView commitAnimations];
2:改变View的自身大小
CGAffineTransform tr = CGAffineTransformScale(self.transform, 0.55, 0.55);
[UIView animateWithDuration:0.1 delay:0 options:0 animations:^{
self.transform = tr;
} completion:^(BOOL finished) {}];
3:通过指定的线条确定动画轨迹
CGPoint fromPoint = CGPointMake(0, 0);
UIBezierPath *movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:fromPoint];
CGPoint toPoint = CGPointMake(300, 460);
[movePath addQuadCurveToPoint:toPoint
controlPoint:CGPointMake(toPoint.x,fromPoint.y)];//弧线
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = NO;
moveAnim.duration = 2;
[moveAnim setRepeatCount:2];
[self.view1.layer addAnimation:moveAnim forKey:nil];
4: View 旋转180度
CGAffineTransformRotate(self.colTypeImageView.transform, 3.14 )
5:View 左右抖动动画
- (void) shakeAnimationWithControl:(UIView *)view {
CAKeyframeAnimation *keyAn = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[keyAn setDuration:0.5f];
NSArray *array = [[NSArray alloc] initWithObjects:
[NSValue valueWithCGPoint:CGPointMake(view.center.x, view.center.y)],
[NSValue valueWithCGPoint:CGPointMake(view.center.x-5, view.center.y)],
[NSValue valueWithCGPoint:CGPointMake(view.center.x+5, view.center.y)],
[NSValue valueWithCGPoint:CGPointMake(view.center.x, view.center.y)],
[NSValue valueWithCGPoint:CGPointMake(view.center.x-5, view.center.y)],
[NSValue valueWithCGPoint:CGPointMake(view.center.x+5, view.center.y)],
[NSValue valueWithCGPoint:CGPointMake(view.center.x, view.center.y)],
[NSValue valueWithCGPoint:CGPointMake(view.center.x-5, view.center.y)],
[NSValue valueWithCGPoint:CGPointMake(view.center.x+5, view.center.y)],
[NSValue valueWithCGPoint:CGPointMake(view.center.x, view.center.y)],
nil];
[keyAn setValues:array];
NSArray *times = [[NSArray alloc] initWithObjects:
[NSNumber numberWithFloat:0.1f],
[NSNumber numberWithFloat:0.2f],
[NSNumber numberWithFloat:0.3f],
[NSNumber numberWithFloat:0.4f],
[NSNumber numberWithFloat:0.5f],
[NSNumber numberWithFloat:0.6f],
[NSNumber numberWithFloat:0.7f],
[NSNumber numberWithFloat:0.8f],
[NSNumber numberWithFloat:0.9f],
[NSNumber numberWithFloat:1.0f],
nil];
[keyAn setKeyTimes:times];
[view.layer addAnimation:keyAn forKey:@"TextAnim"];
}
6:切换ViewController或者将应用切换至后台时,动画不停止的方法
shake.removedOnCompletion = NO;
7:使用CAAnimation播放动画完后希望能适应新的坐标变化
[button.layer addAnimation:animationgroup forKey:@"Expand"];
button.center = CGPointMake(button.center.x, button.center.y);
在加入动画以后, 直接设定 动画结束时的坐标即可.