我正在使用如下所示的自定义 segue:
@implementation ModalPushSegue
- (void)perform {
UIViewController *fromController = self.sourceViewController;
UIViewController *toController = self.destinationViewController;
UIView *fromView = fromController.view;
UIView *toView = toController.view;
CGPoint centerStage = toView.centerStage;
toView.center = toView.rightStage;
[fromView.window addSubview:toView];
[fromController addChildViewController:toController];
[UIView transitionWithView:toView
duration:0.5 options:0
animations:^{
toView.center = centerStage;
}
completion:nil];
}
这很好,因为视图按预期从右侧滑动,并且控制器被添加到控制器层次结构中。
但后来在添加的控制器中我这样做:
[self presentViewController:anotherController animated:YES completion:nil];
我希望这会将新控制器的视图向上滑动到屏幕 ala 模态样式。但是发生的事情是新视图没有出现。当我稍后移除这个控制器时,它的视图会闪烁并滑出屏幕,留下黑色背景而不是原来的视图。
我已经玩了一段时间了,如果我将代码更改为
//[self presentViewController:oauthController animated:YES completion:nil];
[self.view addSubview:oauthController.view];
[self addChildViewController:oauthController];
然后视图按预期显示,但未调整大小。
我的问题似乎与 segues 设置层次结构的方式与presentViewController
做事的方式有关。我已经做了很多阅读和搜索,但到目前为止还无法清楚地了解正在发生的事情。
我也玩过在presentViewController
segue 中使用,但不是将新视图放在旧视图上,而是屏幕变黑,然后新视图滑动。
任何帮助表示赞赏。