了解 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. mini-httpd源码分析-match.h

    //字符串匹配,匹配返回 1,否则返回 0. //pattern可以通过任意个 | 字符,组合match_one中pattern的功能 int match(const char* pattern, c ...

  3. 查询linux发行版本号方法总结

      了解Linux发行版本的版本号是一项非常重要的事情,大多数软件对系统的版本都有要求,发行版本号与软件不匹配,软件将无法安装或者无法使用.这边集合市面上流行的Linux发行版本版本号查询方法.有了这 ...

  4. delphi 实现vip126发邮件

    本例是 TSimpleThread , TSimpleList, IdhttpEx 网页模拟(POST)的综合运用. Demo只写了发送,但亦可收取,详见源码. (此源码写于2年前,那时还写得不好,请 ...

  5. Android updater-scripts(Edify Script)各函数详细说明(转)

    这是Android系统来运行updater-scripts的Edify语言的基本介绍. 大部分的Edify命名都是函数,当调用这些函数结束的时候,会返回数据给脚本.当然,你也可以使用这些函数的返回值来 ...

  6. Android之Service与IntentService的比较

    Android之Service与IntentService的比较  不知道大家有没有和我一样,以前做项目或者练习的时候一直都是用Service来处理后台耗时操作,却很少注意到还有个IntentServ ...

  7. ItextSharp代码示例

    示例代码目录 示例代码0101. 5 示例代码0102. 7 示例代码0103. 9 示例代码0104. 11 示例代码0105. 13 示例代码0106. 15 示例代码0107. 17 示例代码0 ...

  8. asp.net MVC Razor 语法(3)

    编程逻辑:执行基于条件的代码. If 条件 C# 允许您执行基于条件的代码. 如需测试某个条件,您可以使用 if 语句.if 语句会基于您的测试来返回 true 或 false: if 语句启动代码块 ...

  9. win7(32 bit) + IE8 环境,IE8无法弹窗(错误提示:“此网页上的错误可能会使它无法正确运行”),有关的系统注册信息损坏——解决方法

    错误截图如下:   IE有关的系统注册信息损坏,导致IE无法正常弹窗.   解决办法:重新注册与IE有关的DLL文件,具体如下: 1.以管理员身份运行附件脚本(新建txt文件,将下面代码复制到txt文 ...

  10. 官网下载旧版本的Xcode

    1.登录“苹果开发者中心”——>“SDKs” 2.点击“Xcode” 3.点击页面顶部的“Download” 4.点击页面左下方的“additional tools”,这样就可以查询到各个Xco ...