旋转动画
来源:互联网 发布:js传值到jsp 编辑:程序博客网 时间:2024/04/30 10:59
整理了一下旋转动画,无限旋转90度的发现当初遇到的一些问题
- (void)HighlightAnimation{
__block typeof(self) Self =self;
[UIViewanimateWithDuration:1.5f
animations:^{
Self.myImageView.transform =CGAffineTransformRotate(Self.myImageView.transform, -M_PI_2);
}
completion:^(BOOL finished) {
[Self DarkAnimation];
}];
}
- (void)DarkAnimation{
__block typeof(self) Self =self;
[UIViewanimateWithDuration:1.5f
animations:^{
Self.myImageView.transform =CGAffineTransformRotate(Self.myImageView.transform,M_PI_2);
}
completion:^(BOOL finished) {
[Self HighlightAnimation];
}];
}
在viewdidload里面调用就会OK
还有一种是如下类型,方法一的动画不是在块里面执行的与上面的有差别啊
在ViewDidLoad里面调用下面的方法即可
//方法1
#pragma mark动画先顺时针旋转90度再逆时针旋转90度
- (void)setAnimated{
UIImage *image = [UIImageimageNamed:@"2"];
self.myImageView= [[UIImageViewalloc]initWithImage:image];
[self.myImageViewsetFrame:CGRectMake(50,120,100,100)];
self.view.backgroundColor= [UIColorwhiteColor];
[self.viewaddSubview:self.myImageView];
[UIViewanimateWithDuration:0
- (void)setAnimated{
UIImage *image = [UIImageimageNamed:@"2"];
self.myImageView= [[UIImageViewalloc]initWithImage:image];
[self.myImageViewsetFrame:CGRectMake(50,120,100,100)];
self.view.backgroundColor= [UIColorwhiteColor];
[self.viewaddSubview:self.myImageView];
[UIViewanimateWithDuration:0
delay:0
options:UIViewAnimationOptionRepeat
animations:^{
[UIViewsetAnimationDuration:1.5f];
self.myImageView.transform=CGAffineTransformIdentity;
self.myImageView.transform=CGAffineTransformRotate(self.myImageView.transform,M_PI_2);
} completion:^(BOOLfinished) {
[self.myImageViewremoveFromSuperview];
[UIViewanimateWithDuration:0
[UIViewsetAnimationDuration:1.5f];
self.myImageView.transform=CGAffineTransformIdentity;
self.myImageView.transform=CGAffineTransformRotate(self.myImageView.transform,M_PI_2);
} completion:^(BOOLfinished) {
[self.myImageViewremoveFromSuperview];
[UIViewanimateWithDuration:0
delay:0
options:UIViewAnimationOptionRepeat
animations:^{
[UIViewsetAnimationDuration:1.5f];
self.myImageView.transform=CGAffineTransformRotate(self.myImageView.transform, -M_PI_2);
} completion:^(BOOLfinished) {
}];
}];
}
//方法2
#pragma mark动画先顺时针旋转90度再逆时针旋转90度
/*
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//离屏后会remove animation,这里重新添加
[self startAnimatew];
//程序从后台进入激活状态需要重新添加Animation
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startAnimatew) name:@"kAPPEnterForeground" object:nil];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"kAPPEnterForeground" object:nil];
}
*/
- (UIImageView*)createImageViewWithFrame:(CGRect)frame tag:(NSInteger)tag named:(NSString*)name{
UIImageView *imageView = [[UIImageViewalloc]initWithFrame:frame];
imageView.tag= tag;
imageView.image= [UIImageimageNamed:name];
return imageView;
}
- (void)createSubView{
_firstView = [[UIViewalloc]initWithFrame:CGRectMake(60,40,60,60)];
[self.viewaddSubview:_firstView];
CGRect frame = self.firstView.bounds;
UIImageView *imageView = [selfcreateImageViewWithFrame:frametag:kTAG_BASE_VALUEnamed:@"2.jpg"];
//定位点,不写默认是中心点
// imageView.layer.anchorPoint = CGPointMake(28/45, 16/45);
imageView.frame= frame;
[self.firstViewaddSubview:imageView];
}
- (void)startAnimatew{
id fromValue = [NSNumbernumberWithFloat:-M_PI_4];
id toValue = [NSNumbernumberWithFloat:M_PI_4];
UIImageView *imageView = [self.firstViewviewWithTag:kTAG_BASE_VALUE];
[selfanimationWithView:imageViewkeyPath:@"transform.rotation.z"fromValue:fromValuetoValue:toValue];
}
- (void)animationWithView:(UIView*)view keyPath:(NSString*)keyPath fromValue:(id)fromValue toValue:(id)toValue{
CAAnimation *animation = [selfcreateAnimationWithKeyPath:keyPathfromValue:fromValuetoValue:toValue];
[view.layeraddAnimation:animationforKey:nil];
}
- (CAAnimation*)createAnimationWithKeyPath:(NSString*)keyPath fromValue:(id)fromValue toValue:(id)toValue{
CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:keyPath];
animation.duration=1.5;//持续时间
CAMediaTimingFunction *mediaTiming = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.timingFunction= mediaTiming;
animation.repeatCount=HUGE_VALF;//重复次数
animation.fromValue= fromValue;//起始角度
animation.toValue= toValue;//终止角度
animation.autoreverses=YES;
return animation;
}
[UIViewsetAnimationDuration:1.5f];
self.myImageView.transform=CGAffineTransformRotate(self.myImageView.transform, -M_PI_2);
} completion:^(BOOLfinished) {
}];
}];
}
//方法2
#pragma mark动画先顺时针旋转90度再逆时针旋转90度
/*
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//离屏后会remove animation,这里重新添加
[self startAnimatew];
//程序从后台进入激活状态需要重新添加Animation
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startAnimatew) name:@"kAPPEnterForeground" object:nil];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"kAPPEnterForeground" object:nil];
}
*/
- (UIImageView*)createImageViewWithFrame:(CGRect)frame tag:(NSInteger)tag named:(NSString*)name{
UIImageView *imageView = [[UIImageViewalloc]initWithFrame:frame];
imageView.tag= tag;
imageView.image= [UIImageimageNamed:name];
return imageView;
}
- (void)createSubView{
_firstView = [[UIViewalloc]initWithFrame:CGRectMake(60,40,60,60)];
[self.viewaddSubview:_firstView];
CGRect frame = self.firstView.bounds;
UIImageView *imageView = [selfcreateImageViewWithFrame:frametag:kTAG_BASE_VALUEnamed:@"2.jpg"];
//定位点,不写默认是中心点
// imageView.layer.anchorPoint = CGPointMake(28/45, 16/45);
imageView.frame= frame;
[self.firstViewaddSubview:imageView];
}
- (void)startAnimatew{
id fromValue = [NSNumbernumberWithFloat:-M_PI_4];
id toValue = [NSNumbernumberWithFloat:M_PI_4];
UIImageView *imageView = [self.firstViewviewWithTag:kTAG_BASE_VALUE];
[selfanimationWithView:imageViewkeyPath:@"transform.rotation.z"fromValue:fromValuetoValue:toValue];
}
- (void)animationWithView:(UIView*)view keyPath:(NSString*)keyPath fromValue:(id)fromValue toValue:(id)toValue{
CAAnimation *animation = [selfcreateAnimationWithKeyPath:keyPathfromValue:fromValuetoValue:toValue];
[view.layeraddAnimation:animationforKey:nil];
}
- (CAAnimation*)createAnimationWithKeyPath:(NSString*)keyPath fromValue:(id)fromValue toValue:(id)toValue{
CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:keyPath];
animation.duration=1.5;//持续时间
CAMediaTimingFunction *mediaTiming = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.timingFunction= mediaTiming;
animation.repeatCount=HUGE_VALF;//重复次数
animation.fromValue= fromValue;//起始角度
animation.toValue= toValue;//终止角度
animation.autoreverses=YES;
return animation;
}
0 0
- 旋转动画
- 旋转动画
- 动画旋转
- 旋转动画
- 旋转动画
- 旋转动画
- 旋转动画
- 旋转动画
- 旋转动画
- 旋转动画
- 动画之旋转动画
- 旋转动画加载, 旋转角度
- Android 动画 - RoateAnimation 旋转动画
- Android动画之旋转动画
- 相机旋转动画
- custom ProgressBar|动画 旋转
- blend 动画旋转
- Jquery旋转动画实现
- 【JAVA】内嵌JettyServer结合springMVC、mybatis实现轻量化系统部署
- animation-list AnimationDrawable null 空指针 原因
- Intent基本介绍
- 按钮 边角 相关设置
- 32位的tetview and medit 在64bit的linux运行,有很多32bit的库没有安装,错误不断之解决办法。
- 旋转动画
- poj 1696
- Java基本语法-----java二维数组
- hdu 1003
- redis范围查询应用-查找IP所在城市<转>
- 控制试图圆角
- @Resource、@Autowired、@Qualifier的注解注入及区别
- 通过继承ListActivity实现列表 了解
- web应用中Spring ApplicationContext的动态更新