了解 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. vb sqlite 使用 litex

    Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal ...

  2. CDC不同模式在ODI中体现系列之一 同步模式

    CDC不同模式在ODI中体现系列之一 同步模式 Oracle Database Change Data Capture feature 变化数据捕获是一个通称,是用来描述捕捉增量变化应用到数据存储.随 ...

  3. _sortBy用法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Choosing Between ElasticSearch, MongoDB &amp; Hadoop

    An interesting trend has been developing in the IT landscape over the past few years.  Many new tech ...

  5. IHttpModule与IHttpHandler的区别整理

    IHttpModule与IHttpHandler的区别整理1.先后次序.先IHttpModule,后IHttpHandler. 注:Module要看你响应了哪个事件,一些事件是在Handler之前运行 ...

  6. sql中将null转换为空

    sql中varchar的默认值为null 当在页面绑定数据时就会出现无法绑定情况此时就需要在查询时转换为空,, isnull(key,'')  key 为字段名,后面的参数就是空值

  7. Matlab中用内建函数代替for循环

    在使用matlab进行矩阵计算的时候,经常会遇到要使用for循环的情况.但其实很多操作可以用内部的一些函数代替. bsxfun, arrayfun, cellfun, spfun, structfun ...

  8. YII与Ace Admin 的集成

    目录 一. 前言... 1 二.为什么要使用YII+ace. 1 三.新建YII模块... 1 四.如何修改模板... 3 五.注意的地方... 4 六.整合的不足之处... 4 一. 前言 yii- ...

  9. R与数据分析旧笔记(十四) 动态聚类:K-means

    动态聚类:K-means方法 动态聚类:K-means方法 算法 选择K个点作为初始质心 将每个点指派到最近的质心,形成K个簇(聚类) 重新计算每个簇的质心 重复2-3直至质心不发生变化 kmeans ...

  10. smarty函数-转载

    Smarty常用函数 2009-08-13 14:05:55|  分类: Php |举报 |字号 订阅   1 .include_once语句: 引用文件路径,路径必需正确.   eg:include ...