了解 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. cv2.imread BGR模式

    openCV 的cv2.imread()导入图片时是BGR通道顺序,这与Matplotlib的显示,或者读取图片的通道不同,如果需要可以转换为RGB模式,以下代码显示不同之处,但BGR在许多地方使用, ...

  2. 复习-C语言内嵌汇编-初级(1)

    打印hello world并改变变量i的值 # include <stdio.h> int main() { ; __asm__( "mov %0, #4\n" :&q ...

  3. 3D模型选中显示样式改变

    osg::ref_ptr<osg::Material> material = new osg::Material(); //模型材质信息 material->setTranspare ...

  4. 7.使用ProcessBuilder执行本地命令(转)

    import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.IO ...

  5. Unix/Linux环境C编程入门教程(4) Debian Linux环境搭建

    Unix/Linux版本众多,我们推荐Unix/Linux初学者选用几款典型的Unix/Linux操作系统进行学习. 1.广义的Debian是指一个致力于创建自由操作系统的合作组织及其作品,由于Deb ...

  6. ldap for ruby

    Net::LDAP for Ruby (also called net-ldap) implements client access for the Lightweight Directory Acc ...

  7. mysql长连接和短连接的问题

    什么是长连接? 其实长连接是相对于通常的短连接而说的,也就是长时间保持客户端与服务端的连接状态. 通常的短连接操作步骤是: 连接->数据传输->关闭连接: 而长连接通常就是: 连接-> ...

  8. 利用KVO监视一个view的frame

    首先,keyPath一定是frame,而不是frame.origin.x之类的路径,因为再点下去的话,就是访问结构体内部的值了,KVO是无法检测的,会报错找不到KeyPath. 代码如下: [_fun ...

  9. 通过案例掌握Spring 管理事务的步骤及配置

    案例描述  通过完成生成订单业务,掌握事务处理.  需要d_order表和d_item表  订单生成时的业务逻辑:向d_order插入1条数据的同时,向t_item中插入若干条数据  这就是一个独立的 ...

  10. asp.net 前台js和后台得到FormView中的控件,以TextBox为例

    一.前台js获取FormView中的控件 js得到前端控件的ID,比如TextBox(这里设置其ID为TextBox1),大家都知道,是document.getElementById("&l ...