gpt4 book ai didi

iOS View Controller 方向

转载 作者:行者123 更新时间:2023-11-29 04:11:01 28 4
gpt4 key购买 nike

我有父 View Controller 和另一个模态视图 Controller 。我在父级上下文中呈现了模态视图 Controller :

readingViewController * reading_view_controller = [[readingViewController alloc] initWithNibName:@"readingViewController" bundle:nil];
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentModalViewController:reading_view_controller animated:YES];

父 View Controller 不会定向横向;所以,我在父 View Controller 中添加了这些方法:

- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationMaskPortrait;
}


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

所呈现的 View Controller (模态呈现)应面向所有可能的方向;所以,我添加了这些方法:

- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{

return YES;
}

但是,因为我假设 (UIModalPresentationCurrentContext),所呈现的 viewController 在 IOS 6.0 中不会定向,而它在 IOS 5.0 中按预期工作

请问这个问题如何解决?

最佳答案

如果您有基于选项卡的应用程序,请首先在应用程序委托(delegate)中添加一些代码以及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;
}

改变该类(class)的方向

-(BOOL)shouldAutorotate
{
return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}

关于iOS View Controller 方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14413081/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com