Dar*_*ren 7 iphone cocoa-touch objective-c uiinterfaceorientation ios
我在MSNavigationPaneViewController 这里使用并且轮换工作.我已经覆盖了我的根中的旋转方法UINavigationController
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController supportedInterfaceOrientations];
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.topViewController != nil) {
return [appDelegate.topViewController preferredInterfaceOrientationForPresentation];
} else {
return UIInterfaceOrientationPortrait;
}
}
Run Code Online (Sandbox Code Playgroud)
我推动MSNavigationPaneViewController使用presentViewController: animated:completion:,我有旋转工作,所以某些视图可以有不同的方向.问题是,每个具有不同方向的视图都需要用户倾斜手机以更改其锁定在正确方向上的方向.我已经完成了大量的阅读以使其工作,似乎我需要preferredInterfaceOrientationForPresentation在每个视图加载之前触发,但它不会触发.我认为它没有触发,因为MSNavigationPaneViewController它没有改变使用的视图控制器presentViewController.这是用于MSNavigationPaneViewController更改视图的代码
- (void)setPaneViewController:(UIViewController *)paneViewController
{
if (_paneViewController == nil) {
paneViewController.view.frame = _paneView.bounds;
_paneViewController = paneViewController;
[self addChildViewController:_paneViewController];
[_paneView addSubview:_paneViewController.view];
[_paneViewController didMoveToParentViewController:self];
} else if (_paneViewController != paneViewController) {
paneViewController.view.frame = _paneView.bounds;
[_paneViewController willMoveToParentViewController:nil];
[self addChildViewController:paneViewController];
void(^transitionCompletion)(BOOL finished) = ^(BOOL finished) {
[_paneViewController removeFromParentViewController];
[paneViewController didMoveToParentViewController:self];
_paneViewController = paneViewController;
};
[self transitionFromViewController:_paneViewController
toViewController:paneViewController
duration:0
options:UIViewAnimationOptionTransitionNone
animations:nil
completion:transitionCompletion];
}
}
Run Code Online (Sandbox Code Playgroud)
看起来它只是切换viewController而不是调用 preferredInterfaceOrientationForPresentation
有没有办法强制preferredInterfaceOrientationForPresentation被调用,或者通过隐藏的视图欺骗它?
谢谢
编辑----
我完全理解新的旋转系统如何在iOS6中运行,并且根据它来管理它.但是preferredInterfaceOrientationForPresentation,如果下一个视图presented使用正确的方法之一,似乎只会调用它.如果窗口刚刚切换,则不会.所以我确实需要一种方法来欺骗这个被调用.
小智 9
您可以通过重置其rootViewController来欺骗窗口重新评估其支持的接口方向.
UIApplication *app = [UIApplication sharedApplication];
UIWindow *window = [[app windows] objectAtIndex:0];
UIViewController *root = window.rootViewController;
window.rootViewController = nil;
window.rootViewController = root;
Run Code Online (Sandbox Code Playgroud)
您需要确保在执行此代码时,根视图控制器的-supportedInterfaceOrientations返回正确的掩码(对应于您希望强制方向的方式).
请注意,此黑客攻击可能会导致屏幕快速闪烁并导致任何正在进行的动画出现故障.
preferredInterfaceOrientationForPresentation将不会在控制器内调用UINavigationController.
您将不得不进行子类化UINavigationController,然后自己实现此功能.你只想委托给topViewController.
如需参考,请访问:http://code.shabz.co/post/32051014482/ios-6-supportedorientations-with-uinavigationcontroller
我还发现了UINavigationController子类的这种实现:https://gist.github.com/3842178
| 归档时间: |
|
| 查看次数: |
6539 次 |
| 最近记录: |