我在横向模式下呈现UINavigationViewController时遇到问题。视图自动旋转为纵向模式。我已经花了大约3个小时来解决这个问题。如果我没有导航控制器,它工作正常。但是,我需要导航控制器,因为我必须从那推出另一个视图控制器。
请提出解决问题的建议。这是代码。
SharingViewController *sharingViewController = [[SharingViewController alloc] initWithNibName:@"SharingViewController" bundle:nil];
UINavigationController *navi = [[[UINavigationController alloc] initWithRootViewController:sharingViewController] autorelease];
[navi setWantsFullScreenLayout:YES];
[navi.view setAutoresizesSubviews:NO];
[navi.navigationBar setHidden:YES];
navi.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
navi.visibleViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:navi animated:YES];
答案 0 :(得分:1)
如果你这样做:
SharingViewController *sharingViewController = [[SharingViewController alloc] initWithNibName:@"SharingViewController" bundle:nil];
sharingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
UINavigationController *navi = [[[UINavigationController alloc] initWithRootViewController:sharingViewController] autorelease];
navi.modalPresentationStyle = UIModalPresentationCurrentContext;
...
[[self navigationController] presentModalViewController:navi animated:YES];
它应该有用。我有同样的问题,但当我将 modalPresentationStyle 属性添加到viewController和UINavigationController时,它开始工作。