我正在使用自定义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];
我希望这会将新控制器的视图向上移动到屏幕上的模式样式。但相反的是,新视图不会出现。当我稍后移除此控制器时,它的视图会闪烁并从屏幕上滑落,留下黑色背景而不是原来的视图。
如果我将代码更改为
,我已经玩了一段时间了//[self presentViewController:oauthController animated:YES completion:nil];
[self.view addSubview:oauthController.view];
[self addChildViewController:oauthController];
然后视图按预期显示,但未调整大小。
我的问题似乎是segues设置层次结构与presentViewController
执行事务的方式。我已经做了很多阅读和搜索,但到目前为止还没有能够清楚地了解究竟发生了什么。
我还在segue中使用presentViewController
,但不是将新视图放在旧视图上,屏幕变黑,然后新视图会滑动。
任何帮助表示感谢。
答案 0 :(得分:1)
在目标视图控制器上设置故事板ID(在故事板中),然后尝试以下代码:
AnotherController *viewC = [self.storyboard instantiateViewControllerWithIdentifier:@"AnotherController"];
ModalPushSegue *segue = [[ZHCustomSegue alloc] initWithIdentifier:@"coolSegueName" source:self destination:viewC];
[segue perform];