资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

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

可以将UIView对象的位置及尺寸变化处理成动画效果

创新互联建站自2013年起,先为新都等服务建站,新都等地企业,进行企业商务咨询服务。为新都企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

  • 基本的动画处理方式

//标识动画的开始位置
+ (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;


分享标题:UIKit框架(3)UIView的动画处理方式
本文来源:http://cdkjz.cn/article/pddijd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220