Storyboard 自定义转场动画
2024-08-24 21:11:27
在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,segue的类型是不同的。在iphone中,segue 有:push,modal,和custom三种不同的类型,这些类型的区别在与新页面出现的方式。而在ipad中,有 push,modal,popover,replace和custom五种不同的类型。
1 自定义DetailStoryboardSegue类继承于UIStoryboardSegue
// 这个类用于处理跳转动画 - (instancetype)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination { self = [super initWithIdentifier:identifier source:source destination:destination]; if (self) { } return self; } - (void)perform { // 如果使用系统的转场动画则不注释,如果使用自定义转场动画则重写该放法。 // [super perform]; // 自定义转成动画代码部分 UIViewController *source = self.sourceViewController; UIViewController *destination = self.destinationViewController; // Create a UIImage with the contents of the destination UIGraphicsBeginImageContext(destination.view.bounds.size); [destination.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *destinationImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // Add this image as a subview to the tab bar controller UIImageView *destinationImageView = [[UIImageView alloc] initWithImage:destinationImage]; [source.parentViewController.view addSubview:destinationImageView]; // Scale the image down and rotate it 180 degrees (upside down) CGAffineTransform scaleTransform = CGAffineTransformMakeScale(0.1, 0.1); CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(M_PI); destinationImageView.transform = CGAffineTransformConcat(scaleTransform, rotateTransform); // Move the image outside the visible area CGPoint oldCenter = destinationImageView.center; CGPoint newCenter = CGPointMake(oldCenter.x - destinationImageView.bounds.size.width, oldCenter.y); destinationImageView.center = newCenter; // Start the animation [UIView animateWithDuration:0.5f delay: options:UIViewAnimationOptionCurveEaseOut animations:^(void) { destinationImageView.transform = CGAffineTransformIdentity; destinationImageView.center = oldCenter; } completion: ^(BOOL done) { // Remove the image as we no longer need it [destinationImageView removeFromSuperview]; // Properly present the new screen [source.navigationController pushViewController:destination animated:nil]; }]; }
2 在Storyboard中设置
最新文章
- 视图(View) – ASP.NET MVC 4 系列
- 从C#到Objective-C,循序渐进学习苹果开发(5)--利用XCode来进行IOS的程序开发
- 编写高性能Javascript代码的若干建议
- Linux下的一个图形管理工具webmin
- jQuery Mobile 移动开发中的日期插件Mobiscroll使用说明
- 使用 eclipse+egit 将项目提交至 github ,本地的git仓库:eclipse工作项目目录
- 当月 当年sql
- python2.7抓取豆瓣电影top250
- JavaScript高级程序设计39.pdf
- final关键字的作用
- [Cocos2d-x]Lua 资源热更新
- Linux程序设计综合训练之简易Web服务器
- 定时跳转的两种方式(html + javaweb)
- Day 5-4封装.__隐藏属性或者方法
- Django 学习第三式
- 移动APP漏洞趋势
- [javaSE] 基本类型(String相关)
- September 21st 2017 Week 38th Thursday
- 北京Uber优步司机奖励政策(11月2日~11月8日)
- HDU 5116 Everlasting L