- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做一些“有趣的” View 转换,并且我发现自己正在以一种感觉不正确的方式处理“presentModalViewController”的功能。
我更愿意完全控制模态视图 Controller View 的呈现,并完全跳过“presentModalViewController”。
但是,我不确定这样做的后果。
目前,我的代码看起来像这样工作(这只是一个伪代码示例,我无法使用内置转换,它们不会执行我需要的操作):
// Create the child view controller:
ModalViewController * child = [[ModalViewController alloc] init];
// Present it:
[parentViewController presentModalViewController:child animated:NO];
// This rect is what the child view's ultimate "destination" should be,
// and, what the parent view's old frame was:
CGRect frame = child.view.frame;
// Put the parent view controller's view back in the window:
[child.view.window insertSubview:parentViewController.view belowSubview:child.view];
// Show it if it's hidden:
[parentViewController.view setHidden:NO];
// Put the parent back where it was:
[parentViewController.view setFrame:frame];
// Put the child at the "top" of the screen (the bottom edge
// of the child's view is at the top of the screen):
[child.view setFrame:CGRectMake(frame.origin.x,
frame.origin.y - frame.size.height,
frame.size.width,
frame.size.height)];
// Animate a transition which slide the parent and child views
// down together:
[UIView animateWithDuration:0.7 animations:^(void) {
child.view.frame = frame;
parentViewController.view.frame = CGRectMake(frame.origin.x,
frame.origin.y + frame.size.height,
frame.size.width,
frame.size.height);
} completion:^(BOOL finished) {
// We're done, remove the parent view from the window
// like it's supposed to be:
[parentViewController.view removeFromSuperview];
}];
[child release];
最佳答案
如果您不想让 UIKit
设置 modalViewController
并控制 subview Controller 的呈现和解除,那就不要这样做。您可以跳过 presentModalViewController:animated:
调用并手动添加或删除 subview ,或者如果您想切换到全新的 View Controller ,则断开旧 View Controller 的 view
与其他呈现方式包括 UINavigationController 或 UITabBarController ,它们不使用 modalViewController 方法。
更具体地说,您应该设置 rootViewController
将应用程序的 UIWindow
属性添加到新的 View Controller 。
文档说:
The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller’s view as the content view of the window. If the window has an existing view hierarchy, the old views are removed before the new ones are installed.
请注意,文档提到了将 View
安装为层次结构的内容 View 的自动过程。我的意思是,您可以使用提供的自动方法 - UIWindow
用于 Root View ,modalViewController
和其他系统用于非 Root View - 或者您也可以手动执行,但它正在完成同样的事情。特别是 rootViewController
属性自 iOS 4 起才存在,在此之前的应用程序在启动时使用自动生成的默认代码 [window addSubview:rootView]
。
如果 UIKit
在 [UIWindow setRootViewController:]
中发生了一些额外的魔法,我完全准备好对此进行纠正。
关于ios - 我必须使用 Present Modal ViewController 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7115761/
我现在在另一个 ViewController 之上展示了一个几乎透明的 ViewController,但它禁用了与下面的 ViewController 的交互。这是我目前使用的代码: topContr
我有一个 View Controller ,其工具栏上有 3 个 UIButtons,可以打开一个新的 View Controller 作为弹出窗口。我在 Storyboard 中创建了 Segues
这个问题在这里已经有了答案: Delegates in swift? (15 个答案) 关闭 3 年前。 在我的场景中,我试图在关闭 View Controller 期间将值从 ViewContro
假设我有两个 viewController,AViewController 和 BViewController。 AViewController 嵌入在 NavigationController 中(
我有 3 个 View Controller A、B 和 C。 我在 vcA 上,我使用 推送 vcB [self.navigationController pushViewController:vc
我想知道如何在 VC3 和 VC1 之间传递数据。 我拥有的是 Root View (VC1)。然后你输入一个tableView,如果你选择一个项目,你将进入tableView2(VC3) - 类别
我在使用 Unwind Segue 时遇到问题。我有 3 个 ViewController,它们都在名为 ViewController.swift 的类下。我试图获取最后一个 ViewControll
我有一个应用程序,其左上角有一个汉堡菜单。按下时,菜单会以 90% 的不透明度淡入当前 ViewController,显示应用程序的主要导航选项。 我使用下面的代码从页面呈现 viewControll
我的问题是,当我呈现一个 UIViewController 时,呈现的 View 变黑了。 我有一个名为 mainViewController 的 UIViewController,它是我窗口的 Ro
例如,当我呈现UIActivityViewController或UIAlertController时,我仍然可以看到背景viewController,我不想在viewContollerA中嵌入view
我从second viewController进入了third viewController,但是我不想回到第二个viewController,我需要直接回到我的第一个viewController,我
我的应用程序是标签栏(+ 导航)应用程序。在 FirstViewController 中,我调用 onModalView。 -(void) onFilter { FilterViewControl
Photo Sharing 部分是我写的一个ViewController,当我按下正确的项目时,PhotoSharingViewController 会动画出现。 这是我的代码: PhotoShari
我正在尝试在另一个 View Controller 中使用 subview Controller 的应用程序。我有一个 VC,我正在实例化另一个 VC,并在外部 VC 内使用它自己的 xib。 我使用
我正在寻找有关包含 ViewController 的滚动的想法。我需要知道包含 View Controller 的位置。我已经尝试过 UIPageViewController 但我无法让滚动委托(de
我有一个带有嵌入式 NavigationController 的基本 ViewController 来提供工具栏。 ToolBar 有三个按钮,用于通过 segue 调用 ViewController
我的应用程序中的伙计们,我在应用程序委托(delegate)方法中有一些代码 application:didFinishLaunchingWithOptions:确定初始 View Controlle
我遇到了一个问题,我将对此进行描述,并且发现了一些类似的问题,但我认为与我的问题无关。 我有一个 UITabBarController,其中有 2 个用于 VC1 和 VC2 的选项卡。 VC1 转到
我的应用程序中有一个计时器。如果计时器达到 0,则用户将被带到失败页面。当这种情况发生时,之前的 ViewController 没有被关闭,导致更多的内存被占用。 如果出现失败页面,我希望关闭之前的
在问这个问题之前,我当然做了一些调查。我在 google 和 stackoverflow 上找到的链接或主题之一是: How do I load another view controller fro
我是一名优秀的程序员,十分优秀!