#import "ViewController.h"

@interface ViewController ()

{

UIImageView *imgView;

BOOL flag;

UIImageView *imgView1;

UIImageView *imgView2;

UIImageView *imgView3;

UIButton *btn1;

UIButton *btn2;

UIButton *btn3;

}

@end

@implementation ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

self.view.backgroundColor = [UIColor whiteColor];

flag = YES;

btn1 = [UIButton buttonWithType:UIButtonTypeCustom];

btn1.frame = CGRectMake(250, 200, 60, 60);

//    btn1.hidden = YES;

[self.view addSubview:btn1];

imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];

imgView1.layer.cornerRadius = 30;

imgView1.layer.masksToBounds = YES;

imgView1.image = [UIImage imageNamed:@"1.png"];

[btn1 addSubview:imgView1];

btn2 = [UIButton buttonWithType:UIButtonTypeCustom];

btn2.frame = CGRectMake(250, 200, 60, 60);

//    btn2.hidden = YES;

[self.view addSubview:btn2];

imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];

imgView2.layer.cornerRadius = 30;

imgView2.layer.masksToBounds = YES;

imgView2.image = [UIImage imageNamed:@"2.png"];

[btn2 addSubview:imgView2];

btn3 = [UIButton buttonWithType:UIButtonTypeCustom];

btn3.frame = CGRectMake(250, 200, 60, 60);

//    btn3.hidden = YES;

[self.view addSubview:btn3];

imgView3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];

imgView3.layer.cornerRadius = 30;

imgView3.layer.masksToBounds = YES;

imgView3.image = [UIImage imageNamed:@"3.png"];

[btn3 addSubview:imgView3];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

button.frame = CGRectMake(250, 200, 60, 60);

[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button];

imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];

imgView.layer.cornerRadius = 30;

imgView.layer.masksToBounds = YES;

imgView.image = [UIImage imageNamed:@"01.png"];

[button addSubview:imgView];

}

-(void)click:(id)sender

{

if (flag)

{

[UIView animateWithDuration:0.5 animations:^{

imgView.transform = CGAffineTransformMakeRotation(3.14);

//             [btn1.layer addAnimation:[self moveX:2.0f X:[NSNumber numberWithFloat:-150.0f]] forKey:nil];

//            [btn3.layer addAnimation:[self moveX:1.0f X:[NSNumber numberWithFloat:200.0f]] forKey:nil];

[btn1.layer addAnimation:[self moveX:1.0 X:[NSNumber numberWithFloat:-150.0f] Direction:0] forKey:nil];

[btn2.layer addAnimation:[self moveX:1.0 X:[NSNumber numberWithFloat:-150.0f] Direction:1] forKey:nil];

//            [btn3.layer addAnimation:[self moveX:2.0 X:[NSNumber numberWithFloat:0] Direction:2] forKey:nil];

CGPoint point = CGPointMake(-100, -100);

[btn3.layer addAnimation:[self movepoint:point time:1.0] forKey:nil];

//            [btn1.layer addAnimation:[self rotation:2.0 degree:0.78 direction:360 repeatCount:1] forKey:nil];

[UIView animateWithDuration:0.5 animations:^{

btn1.transform = CGAffineTransformMakeRotation(M_PI);

btn2.transform = CGAffineTransformMakeRotation(M_PI);

btn3.transform = CGAffineTransformMakeRotation(M_PI);

}];

}];

flag=NO;

}

else

{

[UIView animateWithDuration:0.5 animations:^{

imgView.transform = CGAffineTransformIdentity;

//            [btn1.layer addAnimation:[self moveX:2.0f X:[NSNumber numberWithFloat:0.0f]] forKey:nil];

[btn1.layer addAnimation:[self moveX:1.0f X:[NSNumber numberWithFloat:0.0f] Direction:0] forKey:nil];

[btn2.layer addAnimation:[self moveX:1.0f X:[NSNumber numberWithFloat:0.0f] Direction:1] forKey:nil];

CGPoint point = CGPointMake(0, 0);

[btn3.layer addAnimation:[self movepoint:point time:1.0] forKey:nil];

[UIView animateWithDuration:0.5 animations:^{

btn1.transform = CGAffineTransformMakeRotation(0);

btn2.transform = CGAffineTransformMakeRotation(0);

btn3.transform = CGAffineTransformMakeRotation(0);

}];

}];

flag=YES;

}

}

#pragma mark =====横向、纵向移动===========

//横向或者纵向移动

-(CABasicAnimation *)moveX:(float)time X:(NSNumber *)x Direction:(NSUInteger)tag

{

//    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];///.y的话就向下移动。

CABasicAnimation *animation = [[CABasicAnimation alloc] init];///.y的话就向下移动。

if (tag == 0)//横向,改变X

{

animation.keyPath = @"transform.translation.x";

animation.toValue = x;

}

else if (tag == 1)//纵向,改变Y

{

animation.keyPath = @"transform.translation.y";

animation.toValue = x;

}

animation.duration = time;

animation.removedOnCompletion = NO;//yes的话,又返回原位置了。

//    animation.repeatCount = MAXFLOAT;

animation.repeatCount = 1;

animation.fillMode = kCAFillModeForwards;

return animation;

}

//移动到某个点

-(CABasicAnimation *)movepoint:(CGPoint )point time:(float)time//点移动

{

CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation"];

animation.toValue=[NSValue valueWithCGPoint:point];

animation.removedOnCompletion=NO;

animation.duration = time;

animation.fillMode=kCAFillModeForwards;

return animation;

}

//旋转

-(CABasicAnimation *)rotation:(float)dur degree:(float)degree direction:(int)direction repeatCount:(int)repeatCount

{

CATransform3D rotationTransform  = CATransform3DMakeRotation(degree, 0, 0,direction);

CABasicAnimation* animation;

animation = [CABasicAnimation animationWithKeyPath:@"transform"];

animation.toValue= [NSValue valueWithCATransform3D:rotationTransform];

animation.duration= dur;

animation.autoreverses= NO;

//    animation.cumulative= YES;

animation.removedOnCompletion=NO;

animation.fillMode=kCAFillModeForwards;

animation.repeatCount= repeatCount;

animation.delegate= self;

return animation;

}

iOS 动画 旋转 移动简单代码的更多相关文章

  1. iOS 动画效果。简单的提示消失

    UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(, , , )]; label1.text = @"qingjoin& ...

  2. UI设计篇·入门篇·简单动画的实现,透明动画/旋转动画/移动动画/缩放动画,混合动画效果的实现,为动画设置监听事件,自定义动画的方法

    基本的动画构成共有四种:透明动画/旋转动画/移动动画/缩放动画. 配置动画的方式有两种,一种是直接使用代码来配置动画效果,另一种是使用xml文档配置动画效果 相比而言,用xml文档写出来的动画效果,写 ...

  3. (转)iOS动画Core Animation

    文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animat ...

  4. IOS 动画专题 --iOS核心动画

    iOS开发系列--让你的应用“动”起来 --iOS核心动画 概览 通过核心动画创建基础动画.关键帧动画.动画组.转场动画,如何通过UIView的装饰方法对这些动画操作进行简化等.在今天的文章里您可以看 ...

  5. IOS动画(Core Animation)总结 (参考多方文章)

    一.简介 iOS 动画主要是指Core Animation框架.官方使用文档地址为:Core Animation Guide. Core Animation是IOS和OS X平台上负责图形渲染与动画的 ...

  6. iOS动画学习

    学习一下动画,感谢以下大神的文章:    UIView:基础动画.关键帧动画.转场动画 Core Animation :基础动画,关键帧动画,动画组,转场动画,逐帧动画 CALayer :CALaye ...

  7. iOS 动画笔记 (一)

    你也肯定喜欢炫酷的动画! 在APP中,动画就是一个点睛之笔!可以给用户增加一些独特的体验感,估计也有许多的和我一样的,看着那些觉得不错的动画,也就只能流口水的孩子,毕竟可能不知道从哪里下手去写!动画学 ...

  8. iOS 动画Animation - 5:UIBezier

    首先说明:这是一系列文章,參考本专题下其它的文章有助于你对本文的理解. 在之前的bolg中大家会发现总是会出现UIBezier,可是我也没有做过多介绍,今天就集中介绍一下UIBezier.首先.UIB ...

  9. iOS动画浅汇

    转自:http://www.cocoachina.com/ios/20160311/15660.html 在iOS开发中,制作动画效果是最让开发者享受的环节之一.一个设计严谨.精细的动画效果能给用户耳 ...

随机推荐

  1. RecyclerView使用总结

    遇到的异常: java.lang.ExceptionInInitializerError静态块初始化异常 NetworkOnMainThreadException访问网线不能在主线程中进行 我的参考资 ...

  2. [课程设计]Scrum 1.5 多鱼点餐系统开发进度(点餐页面框架修复及继续布置)

    Scrum 1.5 多鱼点餐系统开发进度(点餐页面框架修复及继续布置)  1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅 ...

  3. noi 1944 吃糖果

    题目链接:http://noi.openjudge.cn/ch0206/1944/ 根据第一天吃的个数递推,发现这个递推关系很像斐波那契数列. http://paste.ubuntu.com/2340 ...

  4. (3) 深入理解Java Class文件格式(二)

    好文转载:http://blog.csdn.net/zhangjg_blog/article/details/21487287 在上一篇文章 深入理解Java Class文件格式(一) 中, 介绍了c ...

  5. CSS 高级语法 ---- 继承和选择器的分组

    1. 选择器的分组 —————————————————————————   可以对选择器进行分组,被分组的选择器享用共同的声明.   h1,h2,h3,h4,h5,h6 { color: green; ...

  6. 升级PHP

     wget http://down.wdlinux.cn/in/php_up53.shsh php_up53.sh 

  7. 文件上传和下载(可批量上传)——Spring(三)

    在文件上传和下载(可批量上传)——Spring(二)的基础上,发现了文件下载时,只有在Chrome浏览器下文件名正常显示,还有发布到服务器后,不能上传到指定的文件夹目录,如上传20160310.txt ...

  8. 关于js执行顺序

    http://www.cnblogs.com/sanshi/archive/2011/02/28/1967367.html http://mtnt2008.iteye.com/blog/701981 ...

  9. 深入浅出设计模式——桥接模式(Bridge Pattern)

    模式动机设想如果要绘制矩形.圆形.椭圆.正方形,我们至少需要4个形状类,但是如果绘制的图形需要具有不同的颜色,如红色.绿色.蓝色等,此时至少有如下两种设计方案: 第一种设计方案是为每一种形状都提供一套 ...

  10. 聊天界面之气泡文本cell(二)使用Autolayout

    聊天界面主要是cell的动态高度计算和效率的问题,参考网上的两篇文章: 1.优化UITableViewCell高度计算的那些事  http://www.cocoachina.com/ios/20150 ...