可以将UIView对象的位置及尺寸变化处理成动画效果
- <李>
<>强基本的动画处理方式强>
李>//标识动画的开始位置 +,(void) beginAnimations:(NSString *) animationID 上下文:(void *)上下文//标识动画的结束位置,并开始动画 +,commitAnimations (void)//设置动画执行时间,单位为秒, +,(void) setAnimationDuration: (NSTimeInterval) duration ,//动画重复次数,默认为1 +,(void) setAnimationRepeatCount:(浮动)repeatCount
如:通过改变btn的大小使用动画处理
CGRect frame =, self.btn.frame; frame.size.width *=, 1.2; frame.size.height *=, 1.2; [UIView beginAnimations: @“btn”,背景:nil); (UIView setAnimationDuration: 0.5); 时间=self.btn.frame 框架; [UIView commitAnimations];
- <李>
<强>块方式的动画处理强>
李>+,(void) animateWithDuration: (NSTimeInterval) duration 动画:(void (^)(空白))动画 +,(void) animateWithDuration: (NSTimeInterval) duration 动画:(void (^)(空白))animations 完成:(void (^) (BOOL 完成)完成 +,(void) animateWithDuration: (NSTimeInterval) duration 延迟:(NSTimeInterval) delayoptions: (UIViewAnimationOptions) options 动画:(void (^)(空白))animationscompletion: (void (^) (BOOL 完成)完成
如:
CGRect frame =, self.btn.frame; frame.size.width *=, 1.2; frame.size.height *=, 1.2; [UIView animateWithDuration: 0.5,动画:^ { ,,,self.btn.frame =,框架; }];
- <李>
<强>动画处理中使用形变属性强>
李>动画处理中使用形变属性是一个非常好的做法
基于自身初始形变值进行形变:
//位置形变 CGAffineTransform CGAffineTransformMakeTranslation (, CGFloat tx, CGFloat ty );//尺寸形变 CGAffineTransform CGAffineTransformMakeScale (, CGFloat sx, CGFloat sy ),,//旋转形变 CGAffineTransform CGAffineTransformMakeRotation (, CGFloat angle );
基于指定形变值进行形变:
//位置形变 CGAffineTransform CGAffineTransformTranslate (t), CGAffineTransform CGFloat tx, CGFloat ty ),,//尺寸形变 CGAffineTransform CGAffineTransformScale (t), CGAffineTransform CGFloat sx, CGFloat sy );,,//旋转形变 CGAffineTransform CGAffineTransformRotate (t), CGAffineTransform CGFloat angle );
如:
CGAffineTransform transform =, CGAffineTransformScale (self.btn.transform,, 1.2, 1.2); [UIView beginAnimations: @“btn”,背景:nil); (UIView setAnimationDuration: 0.5); 时间=self.btn.transform 转换; [UIView commitAnimations];
形变原始值常量:
const CGAffineTransform CGAffineTransformIdentity;