iOS——自定义Segue实现总结
在阅读了iOS 8自定义动画转场上手指南后,刚开始不理解,后来慢慢消化了,现在总结如下:
1. 自定义Segue关键在于继承UIStoryboardSegue并重写perform方法
2. 动画可以在转场之间的任何方法中添加(Segue的perform方法、prepareSegue、UnwindSegue对应的IBAction方法),但最好统一一下,放在perform中去
3. UnwindSegue关键要在返回的目标VC中定义IBAction,然后才能在Storyboard中通过拖拽并选择IBAction来创建UnwindSegue
4. 创建Segue的时候一定记得要写SegueId(Storyboard中选中Segue后右侧属性列表中有),代码中需要通过id来判断segue
5. -(UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier 一定要在转场目标VC中重写此方法,而不是源VC中
6. 转场动画结束后,记得调用
self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController, animated: false, completion: nil)
或者
self.sourceViewController.dismissViewControllerAnimated(false, completion: nil)
来最终完成segue工作。
7. Segue转场流程:[A performSegueWithIdentifier:sender:] --> [B init] [B awakeFromNib]--> Find segue defined in storyboard by id. --> [A prepareForSegue:sender:](传递数据) --> [customSegue perform] --> [B viewDidload]
UnwindSegue转场流程:[B performSegueWithIdentifier:sender: --> [A segueForUnwindingToViewController:fromViewController:identifier:](Find unwind segue from destination VC's segueForUnwindingToViewController selector.) --> [B prepareForSegue:sender:](传递数据) --> [A -(IBAction)returnFromSegue:(UIStoryboardSegue *)sender] (IBAction relative by unwind segue id which defined in storyboard)
搞定,希望能帮助到有需要的猿!
最新文章
- 如何创建独立的UE4服务端
- DDD开发框架ABP之本地化资源的数据库存储扩展
- NSIS 的简介
- idea中maven项目xml资源文件无法读取
- Unity光照
- 问答精华-IntelliJ IDEA快捷键大全
- Oracle数据库备份与恢复的常用方法
- 【Android 界面效果45】ViewPager源码分析
- 安装centos 7 体验安装过程
- php100 编程小技巧
- php如何修改SESSION的生存时间
- CentOs上搭建git服务器
- 自适应网页设计/响应式Web设计
- 学习python的第一个小目标:通过requests+xlrd实现简单接口测试,将测试用例维护在表格中,与脚本分开。
- 允许mysql用户从远程登录
- SpringBoot+gradle项目构建war
- jupyter notebook 动态图显示
- ubuntu10.04换官方源
- 深入MySQL复制(三):半同步复制
- windows下 zookeeper