您的位置:首页 > 产品设计 > UI/UE

UIKit框架(3)UIView的动画处理方式

2016-02-28 15:43 501 查看
可以将UIView对象的位置及尺寸变化处理成动画效果

基本的动画处理方式
//标识动画的开始位置
+ (void)beginAnimations:(NSString *)animationID context:(void *)context
//标识动画的结束位置,并开始动画
+ (void)commitAnimations
//设置动画执行时间,单位为秒
+ (void)setAnimationDuration:(NSTimeInterval)duration
//动画重复次数,默认为1
+ (void)setAnimationRepeatCount:(float)repeatCount
如:通过改变btn的大小使用动画处理
CGRect frame = self.btn.frame;
frame.size.width *= 1.2;
frame.size.height *= 1.2;
[UIView beginAnimations:@"btn" context:nil];
[UIView setAnimationDuration:0.5];
self.btn.frame = frame;
[UIView commitAnimations];

block方式的动画处理
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delayoptions:(UIViewAnimationOptions)options animations:(void (^)(void))animationscompletion:(void (^)(BOOL finished))completion
如:
CGRect frame = self.btn.frame;
frame.size.width *= 1.2;
frame.size.height *= 1.2;
[UIView animateWithDuration:0.5 animations:^{
self.btn.frame = frame;
}];

动画处理中使用形变属性
动画处理中使用形变属性是一个非常好的做法基于自身初始形变值进行形变:
//位置形变
CGAffineTransform CGAffineTransformMakeTranslation ( CGFloat tx, CGFloat ty );
//尺寸形变
CGAffineTransform CGAffineTransformMakeScale ( CGFloat sx, CGFloat sy );
//旋转形变
CGAffineTransform CGAffineTransformMakeRotation ( CGFloat angle );
基于指定形变值进行形变:
//位置形变
CGAffineTransform CGAffineTransformTranslate ( CGAffineTransform t, CGFloat tx,CGFloat ty );
//尺寸形变
CGAffineTransform CGAffineTransformScale ( CGAffineTransform t, CGFloat sx,CGFloat sy );
//旋转形变
CGAffineTransform CGAffineTransformRotate ( CGAffineTransform t, CGFloat angle );
如:
CGAffineTransform transform = CGAffineTransformScale(self.btn.transform, 1.2, 1.2);
[UIView beginAnimations:@"btn" context:nil];
[UIView setAnimationDuration:0.5];
self.btn.transform = transform;
[UIView commitAnimations];

形变原始值常量:
const CGAffineTransform CGAffineTransformIdentity;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS 对象