在当前视图后面添加完全不同的视图 [英] Adding an entirely different view behind the current view

查看:236
本文介绍了在当前视图后面添加完全不同的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我现在可以做的:
我的UIScreenEdgePanGestureRecognizer能够根据他们举起手指的位置跟随用户的触摸并对适当的位置进行动画。也就是说,如果他们仅仅将视图移动一点,则它回到其原始位置,并且手势识别器被重置。如果用户将其向右移动得足够远并且允许(越过稍微小于屏幕的一半的阈值),则视图从屏幕的右侧滑动,并且主视图滑入视图。 p>

我需要:
将我的顶部详细视图向右移动时, (我使用快照来创建一个UIImageView - 我们称之为dummyMasterview)。我已经采取了主视图,因为它是在我导航之前,显示BEHIND我的当前详细信息视图。我的问题是,函数像addSubView似乎把dummyMasterview作为背景的视图。我想要能够顺利地将顶视图向右拉,以显示它下面的dummyMasterview。然后,当我释放,我将适当地动画的视图(如果超过阈值,一直向下到我的实际根视图)。到目前为止,我只能使用addSubview和其他子视图方法将此图像作为背景在当前视图。

解决方案

好吧,我想出了这一点...我无法添加我的 dummyMasterview在当前可见的视图(让我们称之为currentView)后面,因为我添加它作为currentview的子视图。这导致dummyMasterview只是正在顶部的currentView,不在它后面。要将dummyMasterview放置在 currentView之后,您必须使dummyMasterview成为主窗口的子视图:

  //从图像创建一个dummyMasterView并将其添加为主
//窗口的子视图,以便它在当前可见视图后面显示
UIWindow * mainWindow = [[ UIApplication sharedApplication] keyWindow];
UIImageView * dummyMasterView = [[UIImageView alloc] initWithImage:dummyMasterImage];
UIView * mainWindowSubview = mainWindow.subviews [0];

//将dummyMaster添加到主窗口子视图。
[mainWindowSubview addSubview:self.dummyMasterView];

//移动到后面,所以它不覆盖currentView
[mainWindowSubview sendSubviewToBack:self.dummyMasterView];

基本上,我很傻地假设currentView的子视图将放置BEHIND的currentView。因为我想要一个全新的视图出现在currentView之后,新的视图需要是一个currentView的兄弟。也就是说,currentView和dummyMasterView现在都是主窗口的子视图。一旦我有机会,照片将被张贴以澄清。


Summary: I am trying to implement a pan gesture that works just like Apple's default pan back gesture (interactivePopGestureRecognizer). The only difference is that it snaps all the way back to the primary view of a splitview controller rather than just going back one view on the stack. This is accomplished with popToRootViewController.

What I can currently do: My subclass of the UIScreenEdgePanGestureRecognizer is able to follow the user's touch and animate to the proper location based on where they lift their finger. That is, if they have only moved the view over a little, it snaps back to it original position and the gesture recognizer is reset. If the user moves it to the right far enough and lets go (past a threshold that is slightly less than halfway across the screen), then the view is slid off the right side of the screen and the primary view slides into view.

What I need: While moving my top detail view to the right, I would like to use a snapshot I have taken of the primary view as it was before I navigated away, to show BEHIND my current detail view (I use the snapshot to create a UIImageView - lets call it "dummyMasterview"). My problem is that functions like addSubView seem to place dummyMasterview as a background on that view. I want to be able to smoothly pull the top view to the right to reveal the dummyMasterview below it. Then, when I release, I will animate the view appropriately (popping all the way down to my actual root view if the threshold was crossed). So far I have only been able to use addSubview and the other subview methods to place this image as a background ON the current view. Not as a completely new view behind it.

解决方案

Ok, I figured this out... I was unable to add my "dummyMasterview" behind the currently visible view (let's call it currentView) because I was adding it as a subview of currentView. That results in dummyMasterview just being plopped right on top of currentView, not behind it. In order to place dummyMasterview behind currentView you must make dummyMasterview a subview of the 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];

So basically, I was silly to assume that the subview of currentView would be placed BEHIND that currentView. Since I wanted an entirely new view to appear behind currentView, the new view needed to be a sibling of currentView. That is, both currentView and dummyMasterView are now both subviews of the main window. Pictures will be posted for clarification once I get a chance.

这篇关于在当前视图后面添加完全不同的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆