了解 animateWithDuration方法 制作动画变得不值钱

代码创建一个UIImageView 后加入self.view 容器中

调用点击屏幕touchesBegan 方法执行动画

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,weak)UIImageView * imgview; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
CGFloat cgW=self.view.bounds.size.width;
CGFloat imgW=;
CGFloat imgH=;
CGFloat cgY=(cgW-imgW)*0.5; UIImageView * imgType=[[UIImageView alloc]init];
imgType.frame=CGRectMake(cgY, cgY, imgW, imgH);
imgType.image=[UIImage imageNamed:@"timg"];
imgType.contentMode=UIViewContentModeScaleAspectFill; self.imgview=imgType;
self.imgview.alpha=;//设置透明度
[self.view addSubview:self.imgview]; }
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //动画1
// [self animationPlay1];
//动画2
// [self animationPlay2];
//动画3
// [self animationPlay3];
//动画4
[self animationPlay4];
} /**
动画一
向下滑动
并且消失
*/
-(void)animationPlay1{
/**
animateWithDuration:执行动画的时间
animations:执行的代码
*/
[UIView animateWithDuration:2.0 animations:^{
CGRect temp=self.imgview.frame;
temp.origin.y+=;
self.imgview.alpha=0.1;//设置透明度
self.imgview.frame=temp;
}];
}
/**
向下滑动然后回去
*/
-(void)animationPlay2{
/**
animateWithDuration:执行动画的时间
animations:执行的代码
completion:执行完代码的回调函数
*/
[UIView animateWithDuration:1.5 animations:^{
CGRect temp=self.imgview.frame;
temp.origin.y+=;
self.imgview.frame=temp; } completion:^(BOOL finished) {
CGRect temp=self.imgview.frame;
temp.origin.y-=;
self.imgview.frame=temp; }];
}
/**
向下滑动然后回去延迟1秒钟
*/
-(void)animationPlay3{
/**
animateWithDuration: 动画时间
delay:延迟时间
options:kNilOptions 这个一般设置为kNilOptions 也就是0
animations:要执行的动画代码
completion:回调函数
*/
[UIView animateWithDuration:1.5 delay:1.0 options:kNilOptions animations:^{
CGRect temp=self.imgview.frame;
temp.origin.y+=;
self.imgview.frame=temp;
} completion:^(BOOL finished) {
CGRect temp=self.imgview.frame;
temp.origin.y-=;
self.imgview.frame=temp;
}]; }
/**
放大图片
然后缩放回去
*/
-(void) animationPlay4{
CGFloat cgW=self.view.bounds.size.width;
// CGFloat cgH=self.view.bounds.size.height; CGFloat imgW=self.imgview.bounds.size.width;
CGFloat cgY=(cgW-imgW)*0.5;
[UIView animateWithDuration:1.5 animations:^{
CGRect temp=self.imgview.frame;
temp=CGRectMake(, cgY, self.view.bounds.size.width, self.view.frame.size.height-cgY);
self.imgview.frame=temp;
self.imgview.alpha=0.0;//设置透明度 } completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 animations:^{
CGFloat cgW=self.view.bounds.size.width;
CGFloat imgW=;
CGFloat imgH=;
CGFloat cgY=(cgW-imgW)*0.5;
// CGRect temp=self.imgview.frame;
// temp=CGRectMake(cgY, cgY, imgW, imgH);
self.imgview.alpha=1.0;//设置透明度
self.imgview.frame=CGRectMake(cgY, cgY, imgW, imgH);
}];
}]; } @end

xcode 不值钱的动画UIImageView的更多相关文章

  1. xcode 不值钱的动画UIButton

    #import "ViewController.h" @interface ViewController () /** 按钮 */ @property(nonatomic,weak ...

  2. xcode UIView常用方法属性动画

    常见属性: @property(nonatomic,readonly) UIView *superview; 获得自己的父控件对象 @property(nonatomic,readonly,copy) ...

  3. UIImageView的animationImages动画

    UIImageView的animationImages动画 UIImageView的animationImages,只有在做非常规动画的时候才有优势,比方说下图中左侧动画.如果用来做下图中的右侧动画, ...

  4. Xcode + Swift 制作动态原型

    转载: Xcode + Swift 制作动态原型 为什么是 Xcode 和 Swift 我们尝试过的动态原型设计工具,Origami, Form, Hype, FramerJS,Pixate 等,但都 ...

  5. iOS - 开源框架、项目和学习资料汇总(动画篇)

    动画 1. Core Animation笔记,基本的使用方法 – Core Animation笔记,基本的使用方法:1.基本动画,2.多步动画,3.沿路径的动画,4.时间函数,5.动画组.2. awe ...

  6. iOS开发UI篇—核心动画(UIView封装动画)

    iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...

  7. iOS UIView动画效果 学习笔记

    //启动页动画 UIImageView *launchScreen = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds]; ...

  8. ios基础篇(二十五)—— Animation动画(UIView、CoreAnimation)

    Animation主要分为两类: 1.UIView属性动画 2.CoreAnimation动画 一.UIView属性动画 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIVie ...

  9. UIImageView、UISlider、UISwitch、UIStepper、UISegmentControl

    UIImageView——图像视图 作用:专门用来显示图片的控件 . 设置图像 [self.imageView setImage:[UIImage imageNamed:@"abc.png& ...

随机推荐

  1. ReentrantLock(重入锁)以及公平性

    ReentrantLock(重入锁)以及公平性 标签(空格分隔): java NIO 如果在绝对时间上,先对锁进行获取的请求一定被先满足,那么这个锁是公平的,反之,是不公平的,也就是说等待时间最长的线 ...

  2. rsyslog 配置详解

    格式:: 日志设备(类型).(连接符号)日志级别 日志处理方式(action) 日志设备(可以理解为日志类型): ------------------------ auth –pam产生的日志 aut ...

  3. uva 215 hdu 1455 uvalive5522 poj 1011 sticks

    //这题又折腾了两天 心好累 //poj.hdu数据极弱,找虐请上uvalive 题意:给出n个数,将其分为任意份,每份里的数字和为同一个值.求每份里数字和可能的最小值. 解法:dfs+剪枝 1.按降 ...

  4. Python的迭代器(iterator)和生成器(constructor)

    一.迭代器(iterator) 1.迭代器的概述 在Python中,for循环可以用于Python中的任何类型,包括列表.元祖等等,实际上,for循环可用于任何“可迭代对象”,这其实就是迭代器 迭代器 ...

  5. Android重启应用程序代码

    Intent i = getBaseContext().getPackageManager() .getLaunchIntentForPackage(getBaseContext().getPacka ...

  6. 赵雅智_BroadcastReceiver

    BroadcastReceiver  用于接收程序(包含用户开放的程序和系统内建程序)所发出的Broadcast intent 耗电量 开机启动 窃取别人短信 窃取别人电话 开发: 创建须要启动的Br ...

  7. 判断一个指定的Service是否存在的方法

    这是一个判断一个指定的Service是否存在的方法.它被用于监视一个Service是否由于已经运转,如果由于各种原因Service已经被停止了.这是在重新启动指定Service.它被用于一个Appli ...

  8. GDI+ 填充背景时,非常多时候不起作用,GDI、GDI+配合运用

    在ONDRAW中运行GDI+ 填充背景时,不起作用,不知道什么原因 [cpp] view plaincopy Graphics graphics(pDC->GetSafeHdc()); Bitm ...

  9. 利用Telnet来模拟Http请求 有GET和POST两种

    利用Telnet来模拟Http请求---访问百度.       1.打开"运行"->cmd进入命令环境:       2.输入"telnet www.baidu.c ...

  10. Activity之onWindowFocusChanged

    public void onWindowFocusChanged (boolean hasFocus) 参数hasFocus: the window of this activity has focu ...