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


基本的动画处理方式

//标识动画的开始位置+(void)beginAnimations:(NSString*)animationIDcontext:(void*)context//标识动画的结束位置,并开始动画+(void)commitAnimations//设置动画执行时间,单位为秒+(void)setAnimationDuration:(NSTimeInterval)duration//动画重复次数,默认为1+(void)setAnimationRepeatCount:(float)repeatCount

如:通过改变btn的大小使用动画处理

CGRectframe=self.btn.frame;frame.size.width*=1.2;frame.size.height*=1.2;[UIViewbeginAnimations:@"btn"context:nil];[UIViewsetAnimationDuration:0.5];self.btn.frame=frame;[UIViewcommitAnimations];


block方式的动画处理

+(void)animateWithDuration:(NSTimeInterval)durationanimations:(void(^)(void))animations+(void)animateWithDuration:(NSTimeInterval)durationanimations:(void(^)(void))animationscompletion:(void(^)(BOOLfinished))completion+(void)animateWithDuration:(NSTimeInterval)durationdelay:(NSTimeInterval)delayoptions:(UIViewAnimationOptions)optionsanimations:(void(^)(void))animationscompletion:(void(^)(BOOLfinished))completion

如:

CGRectframe=self.btn.frame;frame.size.width*=1.2;frame.size.height*=1.2;[UIViewanimateWithDuration:0.5animations:^{self.btn.frame=frame;}];


动画处理中使用形变属性

动画处理中使用形变属性是一个非常好的做法

基于自身初始形变值进行形变:

//位置形变CGAffineTransformCGAffineTransformMakeTranslation(CGFloattx,CGFloatty);//尺寸形变CGAffineTransformCGAffineTransformMakeScale(CGFloatsx,CGFloatsy);//旋转形变CGAffineTransformCGAffineTransformMakeRotation(CGFloatangle);

基于指定形变值进行形变:

//位置形变CGAffineTransformCGAffineTransformTranslate(CGAffineTransformt,CGFloattx,CGFloatty);//尺寸形变CGAffineTransformCGAffineTransformScale(CGAffineTransformt,CGFloatsx,CGFloatsy);//旋转形变CGAffineTransformCGAffineTransformRotate(CGAffineTransformt,CGFloatangle);

如:

CGAffineTransformtransform=CGAffineTransformScale(self.btn.transform,1.2,1.2);[UIViewbeginAnimations:@"btn"context:nil];[UIViewsetAnimationDuration:0.5];self.btn.transform=transform;[UIViewcommitAnimations];


形变原始值常量:

constCGAffineTransformCGAffineTransformIdentity;