我的项目中有很多故事板可以提供具有特定功能的模块。在我的一个故事板中,我有一个导航控制器,它推动另一个故事板的初始视图控制器。当我按下它时,导航栏将被删除,并且无法恢复此特定栏。当我在我的新故事板中放置另一个导航控制器时,导航栏会被重置一个丑陋的过渡(它来自右边并替换旧版本)。
这就是我推动我的新故事板视图控制器的方法:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:aStoryboardName bundle:nil];
UIViewController *SideBarInitialViewController = [storyboard instantiateInitialViewController];
UIStoryboardSegue *segue = [[GDFromRightCustomSegue alloc] initWithIdentifier:aSegueIdentifier source:aSource destination:SideBarInitialViewController];
[segue perform];
我也执行自定义segue以摆脱基本动画(来自下方的视图):
UIView *sourceView = [self.sourceViewController view];
UIView *destinationView = [self.destinationViewController view];
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
destinationView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight);
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[window insertSubview:destinationView aboveSubview:sourceView];
[UIView animateWithDuration:0.4 animations:^{
destinationView.frame = CGRectOffset(destinationView.frame, -screenWidth, 0.0);
sourceView.frame = CGRectOffset(sourceView.frame, -screenWidth, 0.0);
} completion:^(BOOL finished){
[self.sourceViewController presentViewController:self.destinationViewController animated:false completion:nil];
}];
有没有办法在没有为导航栏设置动画的情况下推动新的故事板,或者更好的是,在我的新故事板中安装旧的导航控制器?
答案 0 :(得分:0)
在您的源情节提要板中,拖动一个新的 UIViewController ,然后从您的源 ViewController将**模态segue **拖到这个新的 UIViewController 。单击此segue,然后在属性Inspector中添加segue的标识符(假设" newSegue ")标识符必须是唯一的。同时将segue类型设置为" 自定义"并写下" newSegue "在 Segue Class
现在在名为 newSegue 的 UIStoryBoardSegue 上添加一个类别,并在.m文件中写下这两种方法。
- (id) initWithIdentifier:(NSString *)identifier
source:(UIViewController *)source
destination:(UIViewController *)destination
{
return [super initWithIdentifier:identifier
source:source
destination:[[UIStoryboard storyboardWithName:@"YourDestinationStoryBoardName" bundle:nil] instantiateInitialViewController ]];
}
- (void)perform
{
UIViewController *source = (UIViewController *)self.sourceViewController;
[source presentViewController:self.destinationViewController
animated:YES
completion:Nil];
}
现在,在您的源ViewController中,当您想要呈现新的View Controller时,请写下此行
[self performSegueWithIdentifier:@"newSegue" sender:nil];
必须记住替换" YourDestinationStoryBoardName"在上面的函数中使用您的实际目标StoryBoard名称。
试试这个希望这会很好。