在当前视图后面添加一个完全不同的视图

Adding an entirely different view behind the current view

总结: 我正在尝试实现一个平移手势,它的工作方式与 Apple 的默认平移后移手势 (interactivePopGestureRecognizer) 类似。唯一的区别是它会一直返回到 splitview 控制器的主视图,而不是只返回堆栈上的一个视图。这是通过 popToRootViewController 完成的。

我目前能做的事情: 我的 UIScreenEdgePanGestureRecognizer 子类能够跟随用户的触摸并根据他们抬起手指的位置动画到正确的位置。也就是说,如果他们只是稍微移动了视图,它就会快速回到原来的位置,并且手势识别器会被重置。如果用户将它向右移动足够远并放手(超过一个略小于屏幕一半的阈值),则视图从屏幕右侧滑出,主视图滑入视图。

我需要的: 在将我的顶部详细视图向右移动时,我想使用我在导航离开之前拍摄的主视图的快照,以显示我当前详细视图的背后(我使用快照创建一个 UIImageView - 让称之为 "dummyMasterview")。我的问题是像 addSubView 这样的函数似乎将 dummyMasterview 作为该视图的背景。我希望能够顺利地将顶视图向右拉以显示其下方的 dummyMasterview。然后,当我释放时,我将适当地为视图设置动画(如果超过阈值,则一直弹出到我的实际根视图)。到目前为止,我只能使用 addSubview 和其他子视图方法将此图像作为背景放置在当前视图上。不是作为它背后的全新观点。

好的,我想通了...我无法将 "dummyMasterview" 添加到当前可见视图(我们称之为 currentView)后面,因为我将其添加为 currentView 的子视图。这导致 dummyMasterview 只是被放在 currentView 的正上方,而不是在它后面。为了将 dummyMasterview behind currentView 放置,您必须使 dummyMasterview 成为 main window:

的子视图
// Create a dummyMasterView from the image and add it as a subview of the main
// window so it appears behind the current visible view while panning
UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
UIImageView* dummyMasterView = [[UIImageView alloc] initWithImage:dummyMasterImage];
UIView* mainWindowSubview = mainWindow.subviews[0];

 //Add dummyMaster to main window subview.
[mainWindowSubview addSubview:self.dummyMasterView];

 //Move it to the back so it doesn't cover up currentView
[mainWindowSubview sendSubviewToBack:self.dummyMasterView];

所以基本上,我愚蠢地假设 currentView 的子视图将放置在该 currentView 的后面。由于我希望在 currentView 后面出现一个全新的视图,因此新视图需要是 currentView 的同级视图。也就是说,currentView 和 dummyMasterView 现在都是 main window 的子视图。一旦有机会,我会张贴图片以供澄清。