温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-08-06 06:56:08 来源:网络 阅读:334 作者:ymanmeng123 栏目:移动开发

可以将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;



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI