新建一个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. 10秒视频转局部GIF动画

    10秒视频转局部GIF动画,微软出品的一款精致小软件. 百度云盘:http://pan.baidu.com/s/1i3SARfn

  2. Ehcache(2.9.x) - API Developer Guide, Using Explicit Locking

    About Explicit Locking Ehcache contains an implementation which provides for explicit locking, using ...

  3. MVC中使用AuthorizeAttribute注意事项

    代码调用顺序为:OnAuthorization-->AuthorizeCore-->HandleUnauthorizedRequest 如果AuthorizeCore返回false时,才会 ...

  4. asp.net自定义控件

    回发星级控件 using System; using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebContro ...

  5. Ajax之数据连接信息捕获

      connDB.properties: DB_CLASS_NAME=com.mysql.jdbc.Driver DB_URL=jdbc:mysql://127.0.0.1:3306/db_datab ...

  6. WebService中控制字符的处理

    情景     最近项目中很多WebService都发不出去,报的错误如下:    Invalid white space character in text to output (in xml 1.1 ...

  7. PHP学习笔记 - 进阶篇(2)

    PHP学习笔记 - 进阶篇(2) 函数 1.自定义函数 PHP内置了超过1000个函数,因此函数使得PHP成为一门非常强大的语言.大多数时候我们使用系统的内置函数就可以满足需求,但是自定义函数通过将一 ...

  8. OpenGL9-(FreeImage)加载图片-作为纹理

    /*** 这个例子展示如何使用FreeImage加载图片作为纹理* 初学者,在学习OpenGL的时候,往往因为OpenGL读图片没有那么方便* 而浪费了大量的时间在研究图片格式上,其实大可不必. 1. ...

  9. (转)MongoDb的十个使用要点

    从 mongodb 阶段性技术总结 中抽取并整理了对大家有帮助的十个要点:   1.mongodb 表名和字段名统一用小写字母 mongodb 是默认区分大小写的,为了避免以前在 mysql 下遇到的 ...

  10. 如何测量一个嵌入式Linux系统的功耗/power dissipation/power wastage/consumption

    参考: 1.Linux Circuit Software To Calculate Power Dissipation