[英]IOS view controller orientation
我有父視圖控制器和另一個模式視圖控制器。 我在父級上下文中介紹了模式視圖控制器:
readingViewController * reading_view_controller = [[readingViewController alloc] initWithNibName:@"readingViewController" bundle:nil];
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentModalViewController:reading_view_controller animated:YES];
父viewController不會定向Landscape; 因此,我在父viewController中添加了以下方法:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
所呈現的viewController(以模態呈現)應朝向所有可能的方向; 因此,我添加了以下方法:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}
但是,由於我假設(UIModalPresentationCurrentContext),因此呈現的viewController在IOS 6.0中無法正常工作,而在IOS 5.0中卻按預期工作
請問如何解決這個問題?
如果您有一個基於選項卡的應用程序,則首先在應用程序委托中添加一些代碼,並在self.window.rootviewcontroller-self.tabbarcontroller
添加一些代碼。
@implementation UITabBarController (SK8FASTR2App)
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
// your custom logic for rotation of selected tab
if (self.selectedIndex==3){
return UIInterfaceOrientationMaskPortrait;
}
else {
UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight;
return UIInterfaceOrientationMaskAll;
}
}
@end
before
@implementation AppDelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
改變那個班級的方向
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
你應該實現
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
例如:-
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskAll;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.