【发布时间】:2014-01-09 13:46:07
【问题描述】:
有人要求我在两个 UIViewControllers 之间添加完全自定义的过渡,并提出了这个解决方案。它有效,但我不知道是否有更好/更优雅的方式来做到这一点。
完全自定义,我的意思是涉及修改第一个视图控制器子视图(移动它们,不仅仅是淡入淡出或其他),能够改变持续时间等。
我想知道两件事:
- 可以以任何方式分解吗?我可能忘记了一些问题?
- 你觉得这很丑吗?如果是这样,有没有更好的解决方案?
因为几行代码胜过一千个单词,这里有一个非常简单的例子来理解这个想法:
// Considering that self.mainView is a direct subview of self.view
// with exact same bounds, and it contains all the subviews
DCSomeViewController *nextViewController = [DCSomeViewController new];
UIView *nextView = nextViewController.view;
// Add the next view in self.view, below self.mainView
[self.view addSubview:newView];
[self.view sendSubviewToBack:newView];
[UIView animateWithDuration:.75f animations:^{
// Do any animations on self.mainView, as nextView is behind, you can fade, send self.mainView to wherever you want, change its scale...
self.mainView.transform = CGAffineTransformMakeScale(0, 0);
} completion:^(BOOL finished) {
// Push the nextViewController, without animation
[self.navigationController pushViewController:vc animated:NO];
// Restore old
self.backgroundImageView.transform = CGAffineTransformIdentity;
}];
我已经仔细检查了一些我认为可能出错的事情:
- 推送后,视图层次结构没有损坏,一切正常,
self.view发生任何变化 - 弹出时,
nextView不再位于self.view中。
感谢您的意见。
【问题讨论】:
标签: ios objective-c animation uinavigationcontroller pushviewcontroller