Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我必须使用PresentModalViewController吗?_Ios_Core Animation - Fatal编程技术网

Ios 我必须使用PresentModalViewController吗?

Ios 我必须使用PresentModalViewController吗?,ios,core-animation,Ios,Core Animation,我正在做一些“有趣的”视图转换,我发现自己正在以一种感觉不正确的方式处理“presentModalViewController”的功能 我更愿意完全控制模态视图控制器视图的显示,并跳过“presentModalViewController” 然而,我不确定这样做的后果 目前,我有这样的代码(这只是一个伪代码示例,我不能使用内置的转换,它们不能满足我的需要): 如果不想让UIKit设置modalViewController并控制子视图控制器的显示和取消,则不要这样做。您可以跳过“presentMo

我正在做一些“有趣的”视图转换,我发现自己正在以一种感觉不正确的方式处理“presentModalViewController”的功能

我更愿意完全控制模态视图控制器视图的显示,并跳过“presentModalViewController”

然而,我不确定这样做的后果

目前,我有这样的代码(这只是一个伪代码示例,我不能使用内置的转换,它们不能满足我的需要):


如果不想让
UIKit
设置
modalViewController
并控制子视图控制器的显示和取消,则不要这样做。您可以跳过“presentModalViewController:animated:调用并手动添加或删除子视图,或者如果您想切换到全新的视图控制器,则从继承者权限断开旧视图的
视图,然后连接新视图,其他呈现方式包括
UINavigationController
UITabBarController
,它们不使用
modalViewController
方法

更具体地说,您应该将应用程序的
ui窗口的属性设置为新的视图控制器

医生说:

根视图控制器提供窗口的内容视图。将视图控制器指定给此属性(以编程方式或使用Interface Builder)会将视图控制器的视图安装为窗口的内容视图。如果窗口具有现有视图层次结构,则在安装新视图之前将删除旧视图

请注意,文档中提到了将
视图安装为继承人权限的内容视图的自动过程。我想说的是,您可以使用提供的自动方法-
UIWindow
用于根视图,
modalViewController
和其他系统用于非根视图-或者您可以手动执行,但它实现了相同的功能。特别是因为
rootViewController
属性仅在iOS 4之后才存在,在此之前的应用程序在启动时使用了自动生成的默认代码
[window addSubview:rootView]


如果
UIKit
[UIWindow setRootViewController:
中出现了一些额外的魔力,那么我完全准备好对此进行更正。

我认为这不太正确。。。我相信,至少,如果我按照你的建议去做的话,我必须打电话给[child ViewWillExample:…],[child ViewWillEnglish:…]等,以继续向孩子UIViewController提供它应该得到的信息。此外,我认为还有其他问题,如设置父视图控制器引用等。我觉得你太简单了。。。但可能我完全偏离了基准?只要在断开和重新连接视图时在根视图控制器上操作(即从
ui窗口中删除根视图控制器的视图,并将新控制器的子视图添加到其中),所有
视图将
viewDid
事件都应在新视图控制器上触发。
UIKit
的想法是,事件会沿着继承权向下传播,因此只要你确保继承人仍然存在(在你的
UIWindow
下),一切都会完全按照预期工作。@Steve:上述评论的补充,事件传播只在
UIKit
希望你做的范围内工作。因此,
view将出现:
etc将处理视图控制器的即时子视图,该视图控制器由
UIKit
直接显示为当前视图控制器,但如果您在另一个视图控制器中有一个视图控制器(苹果说不要这样做),则不会发送这些消息。如果我在任何地方都使用rootViewController,我得把旧的控制器留在别的地方。此外,您正在使创建任何层次结构变得越来越困难。例如,如果我显示一个模式视图来询问用户一些问题,然后将其忽略,那么我必须在某个地方(可能在堆栈上)保留“最后一个”视图控制器。UIViewController已经有了处理此问题的机制。我认为您离理想的解决方案还有更大的差距。是的,如果您想这样做,请使用
UINavigationController
。你问的是
modalViewController
,我是说你不需要使用
modalViewController
,因为有很多方法可以达到相同的目的(要么同样复杂,要么需要一个额外的变量)。要显示模式视图,需要对其进行初始化,因此只需在对象级别而不是在函数范围内声明该变量。无论您持有对当前内容的引用还是UIKit的引用,实际上都没有第三个选项。
    // 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];