[英]Showing UINavigationController in a Modal segue (ViewController)?
I have now been stuck on this problem for more then 2 weeks! 我已经在这个问题上停留了2个多星期! In my project, I have 1 single ViewController(slide) I want to enable both landscape and portrait in. The rest of all controllers/views(slides) I want to enable portrait-mode only.
在我的项目中,我有1个要同时启用横向和纵向模式的ViewController(幻灯片)。所有其他控制器/视图(幻灯片)的其余部分我仅想启用纵向模式。
The tricky part is, the "ViewController" I am referring to is connected to both NavigationControllers and TabBarControllers. 棘手的部分是,我所指的“ ViewController”同时连接到NavigationControllers和TabBarControllers。 See the scheme below where the ViewController I want to enable both landscape/portrait is named: ReferredViewController.
请参阅下面的方案,其中要同时启用横向/纵向的ViewController的名称为: ReferredViewController。
TabBarController ----> NavigationController ----> FristViewController --(push event)--> ReferredViewController TabBarController ----> NavigationController ----> FristViewController-(推送事件)-> ReferredViewController
So far I have tried to make a CATEGORY for both NavigationControllers and TabBarControllers. 到目前为止,我试图让一个类别两个NavigationControllers和TabBarControllers。 But since my NavigationControllers and TabBarControllers are placed at the very start of the project this will set the rules for the whole project.
但是由于我的NavigationControllers和TabBarControllers放置在项目的最开始,所以这将为整个项目设置规则。 My ReferredViewController is placed at the end or in the middle of the projects "storyboard".
我的ReferredViewController放置在项目“ storyboard”的末尾或中间。 I have tried to set the rules by code aswell for the single ReferredViewController without any success.
我试图通过代码为单个ReferredViewController设置规则,但没有成功。
My best shot is to change the event between FirstViewController and ReferredViewController from "push" to "modal". 我最好的办法是将FirstViewController和ReferredViewController之间的事件从“ push”更改为“ modal”。 ReferredViewController can then rotate both portrait/landscape and the rest of the project is locked in portrait.
然后,ReferredViewController可以同时旋转人像/风景,并且项目的其余部分被锁定为人像。 BUT, as you may know all navigations (NavigationBar) will be lost and the user will become stuck at that single slide.
但是,您可能知道,所有导航(NavigationBar)都将丢失,并且用户将被卡在该单张幻灯片上。
So I am trying to enable the NavigationBar with the following code example in the ReferredViewController.m file: 因此,我尝试在ReferredViewController.m文件中使用以下代码示例启用NavigationBar :
ShowTaskViewController *detailViewController = [[ShowTaskViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentModalViewController:navController animated:YES completion:nil];
[navController release];
[detailViewController release];
But ofc nothing happens and I am back to square one again :O. 但是办公室什么也没有发生,我又回到正题:O。 FML!
FML!
In this line: 在这一行:
[self.navigationController presentModalViewController:navController
animated:YES
completion:nil];
you are conflating two UIViewController instance methods: 您正在混淆两个UIViewController实例方法:
- (void)presentViewController:(UIViewController *)viewControllerToPresent
animated:(BOOL)flag
completion:(void (^)(void))completion
- (void)presentModalViewController:(UIViewController *)modalViewController
animated:(BOOL)animated
The first of these is now the standard, the second method was deprecated in ios6. 第一种方法现已成为标准,第二种方法已在ios6中弃用。
Also the presenting view controller should be self (the ReferredViewController), not self's navigationController. 呈现的视图控制器也应该是self(ReferredViewController),而不是self的navigationController。
Your presented view controller can dismiss itself thus 您呈现的视图控制器可以自行关闭
[[self presentingViewController] dismissViewControllerAnimated:YES
completion:(void (^)(void))completion];
But take a look at fibnochi's answer, it may be a better way for you to achieve your result. 但是,看看fibnochi的答案,这可能是您达到目标的更好方法。
you have to over ride UITaBarController because it is you base view controller. 您必须克服UITaBarController,因为它是基础视图控制器。 I have done this for my navigation controller.
我已经为我的导航控制器完成了此操作。 Tell me if this helped.
告诉我这是否有帮助。
@interface UINavigationController (Autorotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
- (BOOL) shouldAutorotate;
- (NSUInteger) supportedInterfaceOrientations;
@end
@implementation UINavigationController (Autorotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
if ([self.visibleViewController isKindOfClass:[MWPhotoBrowser class]] || [self.visibleViewController isKindOfClass:[ZoomPictureViewController class]]) {
return YES;
}
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL) shouldAutorotate{
return YES;
}
-(NSUInteger) supportedInterfaceOrientations{
if ([self.visibleViewController isKindOfClass:[MWPhotoBrowser class]] || [self.visibleViewController isKindOfClass:[ZoomPictureViewController class]]) {
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.