ios - 如何使用重叠的透明 View Controller 重新创建 FaceTime 的导航 View Controller 转换动画?

标签 ios objective-c uiviewcontroller uinavigationcontroller facetime

简短版:

我想重现 FaceTime 的导航过渡动画,以将透明 View Controller 推送到导航堆栈上,而不会使顶部 View 的内容与底部 View 的内容重叠。

问题:

在标准的 UINavigationController 中,推送具有透明背景的目标 View Controller 会导致难看的动画:源 View Controller 变暗并平移,然后弹出不存在。这是因为标准的导航推送动画假设目标 View Controller 在动画结束时已经完全遮盖了源 View Controller ,当目标 View Controller 的背景是透明时,这个假设就被违反了。请看这个动画:

undesirable navigation push animation

我已经在 https://github.com/bgfriend0/PushVCWithClearBackground 上传了一个重现此行为的演示项目。 .

期望的效果:

但是,Apple 的 FaceTime 应用程序似乎能够推送具有清晰背景的 View Controller ,同时屏蔽掉源 View Controller 的内容,因此推送动画是干净的。请看这个动画:

desired FaceTime navigation push animation

我想重现这种 FaceTime 行为,但我还没有找到解决方案。

研究:

关于这个问题的文献出奇地少。我可以找到一些涉及它的问题(例如 Segue Push Animation with Clear Background is Flashing on iOS 7Views getting darker when are pushed on navigation controller),但没有任何解决方案可以通过重现所需的 FaceTime 效果来实际解决问题。

我在推文 (https://twitter.com/b3ll/status/384114227884986368) 中找到了关于此问题的 Apple 开发论坛的链接,但同样没有找到解决方案:https://devforums.apple.com/message/897379#897379 .

想法:

我提出的唯一可行解决方案与 Caleb Davenport 在 Apple 论坛帖子中提出的解决方案基本相同:

It's got to be one of three things:

(1) They are masking the left view up to the frame of the right view.

(2) They are copying the background contents into the right view while offsetting it such that the right view isn't really transparent.

(3) They are running custom view transitions.

其中每一个都有一定程度的优点,但它们都非常复杂,我忍不住希望应该有一些方便的小旗子 Apple 正在利用它来产生所需的 mask 效果。当然,即使存在这样的标志,它也可能是私有(private) API...不过,我发布这个问题是为了看看是否有人已经想出或可以想出一个优雅的解决方案来重现所需的 FaceTime 透明推送动画。

最佳答案

对于任何可能感兴趣的人,我确实找到了这个问题的答案,因为 Apple 使用私有(private)标志 clipUnderlapWhileTransitioningUINavigationController 上和 _UINavigationParallaxTransition类。

参见,例如:

https://github.com/JaviSoto/iOS8-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UINavigationController.h

https://github.com/JaviSoto/iOS8-Runtime-Headers/blob/master/Frameworks/UIKit.framework/_UINavigationParallaxTransition.h

有了这个标志,我能够完全重现 Facetime 效果。

自然地,所有关于使用私有(private) API 的常见警告都适用于这种情况(即,对于您打算提交到 App Store 的应用程序,这是不允许的)。

关于ios - 如何使用重叠的透明 View Controller 重新创建 FaceTime 的导航 View Controller 转换动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28684783/

相关文章:

ios - UICollectionView 不添加单元格

ios - Swift 3 上的 NotificationCenter 问题

ios - 单行 UILabel 拥抱不适用于自动收缩

ios - 如何在没有 Storyboard的情况下启动另一个 View Controller ?

android - 如何获得有关表情符号的所有信息

ios - 从 Swift 中的超父类(super class)调用初始值设定项?

ios - Xcode在断点位置后停止几行

ios - 在 View Controller 之间传递数据

ios - 获取 UIViewController View 的正确边界

ios - 支持应用程序和扩展程序的 Swift 库