新建一个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. HDU 1003 - Max Sum(难度:*)

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  2. 转:XMPP协议、MQTT协议、HTTP协议、CoAP协议的基本比较

    一.先看下相关国外的专业数据对四大协议的比较: Protocol                                    CoAP                         XMP ...

  3. Python内存解析浅学

    1.内存管理 首先理解变量,和内存特性 1.       Python中无须声明变量, 2.       无须指定类型 3.       不用关心内存管理 4.       变量名会被回收 5.    ...

  4. iOS开发者如何提高自己的水平(转)

    阅读. 把一大堆的知识塞进脑子里.随着时间流逝,终归有一些会留在脑海里.我觉得有些东西读起来还挺有意思,那么也能算作一种愉快的消遣. 分析. 多去熟悉并了解一些工具,从高层的到底层的,不要害怕去使用他 ...

  5. BZOJ 3505

    3505: [Cqoi2014]数三角形 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1171  Solved: 703[Submit][Statu ...

  6. 上传系列:ajaxupload.js

    ajaxupload.js 上次说了jquery.upload.js,这次再说一下ajaxupload.js,这个其实也比较简答,只有一个JS文件: html代码: $(function () { v ...

  7. ContentProvider(一)

    注册ContentProvider: <provider android:name=".provider.UserProvider" android:authorities= ...

  8. Office升级到2013版后无法登录微软账号问题

    自打office从2010版升级到2013版,就再也无法登录微软账号了.每次点击登录,弹出来的框就显示:this feature has been disabled by your administr ...

  9. python遍历目录文件脚本的示例

    例子 自己写的一个Python遍历文件脚本,对查到的文件进行特定的处理.没啥技术含量,但是也记录一下吧. 代码如下 复制代码 #!/usr/bin/python# -*- coding: utf-8 ...

  10. OC6-网址分割

    // // HtmlManger.h // OC6-网址分割 // // Created by qianfeng on 15/6/17. // Copyright (c) 2015年 qianfeng ...