View animations on the iPhone are wonderful. Used properly they will delight your users and help your application stand out. The iOS provides a suite of methods for animating your interface, including the excellent  UIView class method + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations, which takes a block of animations that let you, for example, smoothly resize or move a view or adjust it’s alpha value to fade it in and out.

But what if you want to do a more complex transition? You might be tempted to dip into Core Animation and transformation matrixes. You have complete control over the animation, the timing, callbacks and so on. For a quick flip or other common transformation, though, UIView remains your best friend.

UIView offers two methods for complex animated transitions:

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView 
duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options
completion:(void (^)(BOOL finished))completion
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration
options:(UIViewAnimationOptions)options animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion

These aren’t the most straightforward methods, as the confusion as StackOverflow indicates, and the documentation doesn’t clearly explain what the fromViewtoView and withView should be or even the animations themselves. Yet, for a particular kind of transition, things couldn’t be easier.

In our case we want to transition from one image to another using UIImageView. Specifically we want to flip from one image to the other, with the second image as the backside of the first. Like turning a business card over to view the reverse side.

The first point to be clear on is the views, or view, involved. You might think that a transition will involve two UIImageViews, each displaying a single image, and that we would use the transitionFromView:toView: method. While it might be possible to do it this way, we have it much simpler.

It seems that UIImageView has some transition deliciousness baked right into it.  We don’t actually need two separate image views each holding its own image. UIImageView can perform the transition itself. We only need the single UIImageView and the two images we want. Which means we’ll be using the transitionWithView:method instead.

Make sure you have a UIImageView on the screen and it is already displaying an image. Flip from the first image to the next with a single call to transitionWithView:

UIImageView *imageView = ...;
UIImage *secondImage = ...; [UIView transitionWithView:imageView duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
imageView.image = secondImage;
} completion:nil];

That’s it. With our view in place, the second image loaded, and our animation specified, the UIImageView transition machinery takes care of everything. We end up with a lovely transition from the front side to the back side of a single image view with nothing more than a familiar call to the UIImageView’s image setter.

Animations are awesome. From the start they helped make the iPhone a fun, amazing device. While complex animations can be confusing, the iOS helps, and in many cases you don’t need to look any further than UIKit.

from:http://phildow.net/2012/05/31/flip-an-image-in-uiimageview-using-uiview-transitionwithview/

[转载]Flip an image in UIImageView using UIView transitionWithView的更多相关文章

  1. Java基础 之软引用、弱引用、虚引用 ·[转载]

    Java基础 之软引用.弱引用.虚引用 ·[转载] 2011-11-24 14:43:41 Java基础 之软引用.弱引用.虚引用 浏览(509)|评论(1)   交流分类:Java|笔记分类: Ja ...

  2. [转载]iOS9 使用CoreLocation

    在iOS8之前,只要 #import <CoreLocation/CoreLocation.h>引入CoreLocation.framework. @property (nonatomic ...

  3. [转载]—— Android JNI知识点

    Java Native Interface (JNI)标准是java平台的一部分,它允许Java代码和其他语言写的代码进行交互.JNI 是本地编程接口,它使得在 Java 虚拟机 (VM) 内部运行的 ...

  4. GJM :用JIRA管理你的项目(二)JIRA语言包支持及插件支持 [转载]

    感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...

  5. Ubuntu14.04安装中文输入法以及解决Gedit中文乱码问题[转载]

    转载自:http://www.cnblogs.com/zhcncn/p/4032321.html 写在前面:解决gedit 在txt文件格式出现乱码的问题,在我自己的操作中是需要把系统设置成中文显示环 ...

  6. [转载]Apple Watch 开发详解

    Apple Watch 开发详解 Apple Watch现在对于第三方开发者来说更多的还是一块额外的屏幕.暂时WatchKit没有能给出足够的接口.现在Watch App的主要运算逻辑需要依赖iPho ...

  7. [转载]深入理解Batch Normalization批标准化

    文章转载自:http://www.cnblogs.com/guoyaohua/p/8724433.html Batch Normalization作为最近一年来DL的重要成果,已经广泛被证明其有效性和 ...

  8. Mac上的抓包工具Charles[转载]

    今天就来看一下Mac上如何进行抓包,之前有一篇文章介绍了使用Fidder进行抓包 http://blog.csdn.net/jiangwei0910410003/article/details/198 ...

  9. [转载]kd tree

    [本文转自]http://www.cnblogs.com/eyeszjwang/articles/2429382.html k-d树(k-dimensional树的简称),是一种分割k维数据空间的数据 ...

随机推荐

  1. HP发送HTTP POST请求 返回结果

    HP发送HTTP POST请求 返回结果 <?php $srv_ip = '192.168.10.188';//你的目标服务地址或频道.$srv_port = 80;$url = '/demo/ ...

  2. T-sql GroupBy语句常见问题处理

    1.问题描述 现在有一张course表(含课程编号和名称)和一张sc表(含学生学号,选修课程的编号以及考试成绩),如下:现在想要查询所有课程编号.对应的课程名称以及选修该课程的所有学生的平均成绩.一开 ...

  3. 清北学堂 day6 兔子

    ---恢复内容开始--- [问题描述] 在一片草原上有N个兔子窝,每个窝里住着一只兔子,有M条路径连接这些窝.更特殊地是,至多只有一个兔子窝有3条或更多的路径与它相连,其它的兔子窝只有1条或2条路径与 ...

  4. Mysql加载本地CSV文件

    Mysql加载本地CSV文件 1.系统环境 系统版本:Win10 64位 Mysql版本: 8.0.15 MySQL Community Server - GPL Mysql Workbench版本: ...

  5. easyui页签更新

    1.首先引入这个js文件 <script src="/Scripts/tabs.js" type="text/javascript"></sc ...

  6. Insufficient free space for journal files

    前两天请假了,公司的很多app突然挂掉了,说是mongodb莫名的挂掉了,赶紧进去看了看日志: --31T14:: [initandlisten] ERROR: Insufficient free s ...

  7. mysql存储过程和触发器

    mysql编程(存储过程和触发器) 存储过程 什么是存储过程 存储过程,带有逻辑的sql语句 存储过程特点 执行效率非常快!存储过程是在数据库的服务器端执行的!!! 移植性很差!不同数据库的存储过程是 ...

  8. ubuntu 14.04常见问题

    1. 改root密码 sudo passwd root 2. 显示登录框 sudo gedit /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf 添加 ...

  9. Integer和String "+""=="方法的不同

    在上面的两个篇博客中,我们看到String和Integer不同的常量池的变现形式 我们再看一个例子: public static void main(String[] args) { // TODO ...

  10. 使用#include消除重复代码

    消除重复代码代码很多种,比如: 1)提炼成函数复用 2)使用宏 3)继承 4)使用闭包(boost::bind.boost::function) 上述是最为常用的,对于C++程序,闭包可能用得相对少一 ...