gpt4 book ai didi

ios - 如果开关打开,如何强制所有屏幕的方向处于纵向模式?如果用户旋转它不应该改变它的方向

转载 作者:可可西里 更新时间:2023-11-01 03:55:42 26 4
gpt4 key购买 nike

它是一个父类(super class)文件名Apporientationviewcontroller.h/m。我在所有其他子类中调用这个父类(super class)。因此,如果“isPortraitModeONN”为“ON” 那么所有的屏幕都只能在纵向模式下工作。如果用户尝试将设备更改为横向,则不应旋转。如果开关为“ON”,它应该始终处于纵向模式。在我的情况下,在笑应用程序时它处于纵向模式。但如果我旋转屏幕,它就会变成横向。但它不应该改变方向,直到在设置中打开OFF开关..

  if(isPortraitModeONN)
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
else
{
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft){
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
}
else{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
}

最佳答案

这段代码对我有点用..

 -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:   (id<UIViewControllerTransitionCoordinator>)coordinator
{
///if isPortraitMode On then force the orientation to portrait if it's other than Portrait
///else force the orientation to landscape

if (isPortraitModeONN)
{
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
// do whatever
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsLandscape(orientation)) {
///App is rotating to landscape, force it to portrait
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
{

}];
}
else{

[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
// do whatever
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsPortrait(orientation)) {
///App is rotating to portrait, force it to landscape
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
}];
}
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

关于ios - 如果开关打开,如何强制所有屏幕的方向处于纵向模式?如果用户旋转它不应该改变它的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36785065/

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