新建一个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. JVM 垃圾回收 Minor gc vs Major gc vs Full gc

    关于垃圾回收机制及比较请参见:http://colobu.com/2015/04/07/minor-gc-vs-major-gc-vs-full-gc/ http://colobu.com/2014/ ...

  2. Magento事件机制 - Magento Event/Observer

    为了扩展Magento的功能,我们可以重写Magento的代码,但因为代码只能被重写一次,所以当多个模块需要重写同一部分的代码时,就会引起冲突,好在Magento提供了另一种扩展功能的方法:事件机制, ...

  3. AIDL简单使用

    1.AIDL定义 AIDL是android interface definition language的缩写,它对android IPC组件Binder进行了封装.使用它不需理会底层IPC的实现,只需 ...

  4. JavaScript之图片轮换

    <!doctype html> <title>javascript图片轮换</title> <meta charset="utf-8"/& ...

  5. 第四篇、微信小程序-icon组件

    属性: 效果图: test.wxml <!--成功图标--> <icon type="success" size="40"/> < ...

  6. 关于在windows7中使用Virtual Box 按照 安卓虚拟机几个注意事项

    1.选择安卓原生镜像的问题 选择带PC的字眼的,也就是给平板PC使用的那个,我使用的版本是android-x86-4.0-r1-eeepc.iso其他类似版本也是可以的,因为我已经成功实践啦. 下载地 ...

  7. 手机APP与原生APP设计的区别

    交互上可以按照原生App的设计方式,效果将越来越接近,主要区别在于: 1.设计中要考虑到浏览器地址栏和工具栏的占有空间,和其对App的操作存在一定的影响. 2.暂时不适合调用系统底层接口,更适合web ...

  8. centos7搭建NIS与NFS综合应用

    实验环境: centos7(服务端)        redhat enterprise linux 7.2(客户端) 实验目的:用centos7的账号,能在redhat enterprise linu ...

  9. PHP 魔术方法(所有的魔术方法)

    慢慢长寻夜,明月高空挂. 目前PHP所有的魔术方法有一下这些 __construct() __destruct() __call() __callStatic() __get() __set() __ ...

  10. [Accessibility] Missing contentDescription attribute on image [可取行]失踪contentDescription属性图像

    问题描述: [Accessibility] Missing contentDescription attribute on image [可取行]失踪contentDescription属性图像 原因 ...