gpt4 book ai didi

ios - 如何将一个 View Controller 方向单独强制/锁定到 landscapeRight?

转载 作者:行者123 更新时间:2023-11-28 19:33:15 26 4
gpt4 key购买 nike

我尝试将 shouldAutorotate 设置为 false supportedInterfaceOrientations 到 UIInterfaceOrientationLandscapeRight

-(BOOL)shouldAutorotate{
return NO;
}

-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationLandscapeRight;
}

最佳答案

supportedInterfaceOrientations 就够了,去掉 shouldAutorotate 就可以了。或者你可以这样做。

NavigationController.m

@interface NavigationController : UINavigationController

@end

@implementation NavigationController

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
[super pushViewController:viewController animated:animated];
[self refreshOrientation];
}

- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
id vc = [super popViewControllerAnimated:animated];
[self refreshOrientation];
return vc;
}

- (NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
id vcs = [super popToViewController:viewController animated:animated];
[self refreshOrientation];
return vcs;
}

- (NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
id vcs = [super popToRootViewControllerAnimated:animated];
[self refreshOrientation];
return vcs;
}

- (void)refreshOrientation {
UIViewController *vc = [UIViewController new];
[UIViewController attemptRotationToDeviceOrientation];
[self presentViewController:vc animated:NO completion:nil];
[vc dismissViewControllerAnimated:NO completion:nil];
}
@end

in ViewController implement this method

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft;
}

关于ios - 如何将一个 View Controller 方向单独强制/锁定到 landscapeRight?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41569848/

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