#import"ViewController.h"
@interfaceViewController()
@property(weak,nonatomic)IBOutletUIImageView*imageV;
@property(nonatomic,strong)NSTimer*timer;
@property(nonatomic,assign)BOOLonTransform;
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.onTransform=NO;
}
//翻转
- (IBAction)fanzhuan:(id)sender {
//开始动画
[UIViewbeginAnimations:@"doflip"context:nil];
//设置时长
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseOut];//淡入淡出
[UIViewsetAnimationDelegate:self];
//设置旋转方向
[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.imageVcache:YES];//向上翻页
//[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.imageV cache:YES];//向下翻页
//[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.imageV cache:YES];//沿中间轴旋转
[UIViewcommitAnimations];
}
//旋转
- (IBAction)xuanzhuan:(id)sender {
if(self.onTransform) {
[self.timerinvalidate];
self.timer=nil;
self.onTransform=NO;
}else{
self.timer=[NSTimerscheduledTimerWithTimeInterval:.2target:selfselector:@selector(transformAction)userInfo:nilrepeats:YES];
[self.timerfire];
}
}
//偏移
- (IBAction)pianyi:(id)sender {
[UIViewbeginAnimations:@"move"context:nil];
[UIViewsetAnimationDuration:2];
[UIViewsetAnimationDelegate:self];
//改变它的frame的x,y的值
self.imageV.frame=CGRectMake(100,100,120,100);
[UIViewcommitAnimations];
}
//翻页
- (IBAction)fanye:(id)sender {
[UIViewbeginAnimations:@"curlUp"context:nil];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];//指定动画曲线类型,该枚举是默认的,线性的是匀速的
//设置动画时长
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationDelegate:self];
//设置翻页的方向
[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.imageVcache:YES];
//关闭动画
[UIViewcommitAnimations];
}
//缩放
- (IBAction)suofang:(id)sender {
CGAffineTransformtransform;
transform =CGAffineTransformScale(self.imageV.transform,1.2,1.2);
[UIViewbeginAnimations:@"scale"context:nil];
[UIViewsetAnimationDuration:2];
[UIViewsetAnimationDelegate:self];
[self.imageVsetTransform:transform];
[UIViewcommitAnimations];
}
//取反
- (IBAction)qufang:(id)sender {
CGAffineTransformtransform;
transform=CGAffineTransformInvert(self.imageV.transform);
[UIViewbeginAnimations:@"Invert"context:nil];
[UIViewsetAnimationDuration:2];//动画时常
[UIViewsetAnimationDelegate:self];
[self.imageVsetTransform:transform];//获取改变后的view的transform
[UIViewcommitAnimations];//关闭动画
}
//无限旋转
-(void)transformAction{
self.onTransform=YES;
//创建一个CGAffineTransformtransform对象
CGAffineTransformtransform;
//设置旋转度数
transform =CGAffineTransformRotate(self.imageV.transform,M_PI/20);
[self.imageVsetTransform:transform];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
网友评论