iOS中UIView翻转效果实现
2015-10-28 21:01
459 查看
本文转载至 http://baishiyun.blog.163.com/blog/static/13057117920148228261747/
新建一个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 !");
}
相关文章推荐
- 利用UIScrollView实现展示图片的无限滚动及自动滚动
- ios开发之UIView的frame、bounds跟center属性的区别(附图)
- UIAlertController 警告框
- 浅析UITableViewCell重用机制
- java Vamei快速教程20 GUI
- UVA——10534 Wavio Sequence
- poj 1458 Common Subsequence (最长公共子序列)
- iOS开发UI篇—CAlayer层的属性(一)
- 对QT namespace UI的理解
- jira插件带ui界面和几种方式
- UISlider滑条
- UISearchController
- UITextView
- UIDatePicker
- E - Subsequence
- uestc 1222 Sudoku
- IOS UITableView的分隔线多出问题
- easyUi datebox 默认当天
- UIAlertController replaces the UIActionSheet and UIAlertView
- cordys static value 和 read from message