新建一个view-based模板工程,在ViewController文件中添加下面的代码,即可实现翻转效果;

- (void)viewDidLoad {

[super viewDidLoad];

//需要翻转的视图

UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 200)];

parentView.backgroundColor = [UIColor yellowColor];

parentView.tag = 1000;

[self.view addSubview:parentView];

}

//需要在h头文件声明下面的动作响应函数

//在xib文件中添加一个button,其响应函数为下面的函数

//运行程序后,点击button就看到翻转效果

-(IBAction)ActionFanzhuan{

//获取当前画图的设备上下文

CGContextRef context = UIGraphicsGetCurrentContext();

//开始准备动画

[UIView beginAnimations:nil context:context];

//设置动画曲线,翻译不准,见苹果官方文档

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

//设置动画持续时间

[UIView setAnimationDuration:1.0];

//因为没给viewController类添加成员变量,所以用下面方法得到viewDidLoad添加的子视图

UIView *parentView = [self.view viewWithTag:1000];

//设置动画效果

[UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:parentView cache:YES];  //从上向下

// [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:parentView cache:YES];   //从下向上

// [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:parentView cache:YES];  //从左向右

// [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES];//从右向左

//设置动画委托

[UIView setAnimationDelegate:self];

//当动画执行结束,执行animationFinished方法

[UIView setAnimationDidStopSelector:@selector(animationFinished:)];

//提交动画

[UIView commitAnimations];

}

//动画效果执行完毕

- (void) animationFinished: (id) sender{

NSLog(@"animationFinished !");

}

运行程序,点击按钮,就能看到动画效果了

下面我自己在parentView上添加了两个子视图实现动画

- (void)viewDidLoad {

[super viewDidLoad];

UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 200)];

parentView.backgroundColor = [UIColor yellowColor];

parentView.tag = 1000;

UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];

image1.backgroundColor = [UIColor redColor];

image1.tag = 1001;

UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];

image2.backgroundColor = [UIColor blueColor];

image2.tag = 1002;

[parentView addSubview:image1];

[parentView addSubview:image2];

[self.view addSubview:parentView];

}

-(IBAction)ActionFanzhuan{

CGContextRef context = UIGraphicsGetCurrentContext();

[UIView beginAnimations:nil context:context];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:1.0];

UIView *parentView = [self.view viewWithTag:1000];

[UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:parentView cache:YES];

// [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:parentView cache:YES];

// [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:parentView cache:YES];

// [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES];

NSInteger purple = [[parentView subviews] indexOfObject:[parentView viewWithTag:1002]];

NSInteger maroon = [[parentView subviews] indexOfObject:[parentView viewWithTag:1001]];

[parentView exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];

[UIView setAnimationDelegate:self];

[UIView setAnimationDidStopSelector:@selector(animationFinished:)];

[UIView commitAnimations];

}

- (void) animationFinished: (id) sender{

NSLog(@"animationFinished !");

}

另外:之前在viewDidLoad里面写实现动画的代码,但一致未实现动画效果,原来在viewDidLoad里面执行

CGContextRef context = UIGraphicsGetCurrentContext();

后context的指针为0

iOS的view翻转动画实现--代码老,供参考的更多相关文章

  1. ios阻止锁屏 --老代码,供参考

    // Disable the idle timer [[UIApplication sharedApplication] setIdleTimerDisabled: YES];    // Or fo ...

  2. python读取ini配置文件的示例代码(仅供参考)

    这篇文章主要介绍了python读取ini配置文件过程示范,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 安装 pip install configp ...

  3. c语言 nmealib-0.5.3 学习 简单代码 ,供参考

    void showInfo1(char *buf) { ];// ="$GPGGA,031105.000,4003.9196,N,11620.5765,E,1,05,3.4,109.0,M, ...

  4. iOS开发之各种动画各种页面切面效果

    因工作原因,有段时间没发表博客了,今天就发表篇博客给大家带来一些干货,切勿错过哦.今天所介绍的主题是关于动画的,在之前的博客中也有用到动画的地方,今天就好好的总结一下iOS开发中常用的动画.说道动画其 ...

  5. 【转】iOS开发之各种动画各种页面切面效果

    原文: http://www.cnblogs.com/ludashi/p/4160208.html?utm_source=tuicool 因工作原因,有段时间没发表博客了,今天就发表篇博客给大家带来一 ...

  6. IOS开发系列 --- 核心动画

    原始地址:http://www.cnblogs.com/kenshincui/p/3972100.html 概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥i ...

  7. [iOS Animation]-CALayer 定时器动画

    定时器的动画 我可以指导你,但是你必须按照我说的做. -- 骇客帝国 在第10章“缓冲”中,我们研究了CAMediaTimingFunction,它是一个通过控制动画缓冲来模拟物理效果例如加速或者减速 ...

  8. [iOS Animation]-CALayer 显示动画

    显式动画 如果想让事情变得顺利,只有靠自己 -- 夏尔·纪尧姆 上一章介绍了隐式动画的概念.隐式动画是在iOS平台创建动态用户界面的一种直接方式,也是UIKit动画机制的基础,不过它并不能涵盖所有的动 ...

  9. iOS - Core Animation 核心动画

    1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...

随机推荐

  1. 1、关于Boolean(2015年05月30日)

    背景:刚在看Effective Java,看到一段关于Boolean提供一个返回实例的静态方法的例子,便去看了下Boolean的源码,发现有些内容是之前没注意到的,于是便有了下面这些. 1. Bool ...

  2. 169. Majority Element My Submissions Question

    Total Accepted: 95925 Total Submissions: 239241 Difficulty: Easy Given an array of size n, find the ...

  3. c# using 引用和别名的使用

    1.使用别名 在同时引用的两个命名空间中有相同的类型时,可以使用别名来区分.如下所示: using System; using System.Threading; using System.Timer ...

  4. linux(ubuntu)和windows下面快速搭建android开发环境

    在windows和linux下面搭建android开发环境,一般要安装以下几个软件: 1.JDK安装 2.Eclipse安装 3.Android SDK安装 4.在eclipse里面安装ADT 5.e ...

  5. JQuery验证工具

    一.写法一 var Validator = { // 邮箱isEmail : function(s) {var p = "^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z ...

  6. (转)实战Memcached缓存系统(8)Memcached异步实时读写问题的解决方案SAC

    在使用Memcached时,一般实时读写的场景并不多见.但多是Memcached写入后,在一定时间后才会有读操作.但是如果应用场景,是写入后瞬间即会有读操作呢?似乎没有什么特别之处,我们依然可以这样写 ...

  7. Php的安装与配置

    PHP的安装 php不需要安装,只是一个软件包,在Apache启动的过程中加载即可 PHP的配置 php是一个软件包,只需要在apache启动过程中加载即可,Php对于apache是一个功能模块. 测 ...

  8. spring中jdbc的配置

    本文中的JdbcTemplate的用法可以参看官方文档http://docs.spring.io/spring/docs/3.2.5.RELEASE/spring-framework-referenc ...

  9. What are Upgrade, Product and Package Codes used for? By pusu

    Following content is reprinted from here, please go to the original website for more information. Au ...

  10. 增加用户为SiteCollection的管理员

    1.SiteSettings-->Site collection administrators --> 增加你需要的用户