在 iPad Pro 中不工作的单个 UIViewController 上禁用自动旋转
Disable autorotate on a single UIViewController not working in iPad Pro
我想在 iPhone 和 iPad 中锁定单个 viewcontroller。
以下代码在 iPhone 4,5,6 iPad, iPad 2 ,iPad 视网膜中完美运行。
但不适用于 iPad 专业版。
@implementation UINavigationController (Orientation)
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
@end
上面的代码写在我不想旋转的视图控制器中。
在你不想旋转的视图控制器中写这个
这将防止任何旋转。
你不想旋转的视图控制器class应该有这个。
- (BOOL)shouldAutorotate
{
return NO;
}
The containing navigation controller class should have this.
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutoRotate];
}
这只会旋转到纵向
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
在视图控制器中写下面的代码,你想在纵向模式下锁定哪个视图控制器
@implementation UINavigationController (Orientation)
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
@end
#pragma mark Orientation
-(BOOL)shouldAutorotate
{
[super shouldAutorotate];
return NO;
}
-(NSUInteger) supportedInterfaceOrientations {
[super supportedInterfaceOrientations];
// Return a bitmask of supported orientations. If you need more,
// use bitwise or (see the commented return).
return UIInterfaceOrientationMaskPortrait;
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
[super preferredInterfaceOrientationForPresentation];
// Return the orientation you'd prefer - this is what it launches to. The
// user can still rotate. You don't have to implement this method, in which
// case it launches in the current orientation
return UIInterfaceOrientationPortrait;
}
现在在 plist 文件中的更改下方执行此操作
我想在 iPhone 和 iPad 中锁定单个 viewcontroller。 以下代码在 iPhone 4,5,6 iPad, iPad 2 ,iPad 视网膜中完美运行。 但不适用于 iPad 专业版。
@implementation UINavigationController (Orientation)
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
@end
上面的代码写在我不想旋转的视图控制器中。
在你不想旋转的视图控制器中写这个
这将防止任何旋转。
你不想旋转的视图控制器class应该有这个。
- (BOOL)shouldAutorotate
{
return NO;
}
The containing navigation controller class should have this.
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutoRotate];
}
这只会旋转到纵向
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
在视图控制器中写下面的代码,你想在纵向模式下锁定哪个视图控制器
@implementation UINavigationController (Orientation)
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
@end
#pragma mark Orientation
-(BOOL)shouldAutorotate
{
[super shouldAutorotate];
return NO;
}
-(NSUInteger) supportedInterfaceOrientations {
[super supportedInterfaceOrientations];
// Return a bitmask of supported orientations. If you need more,
// use bitwise or (see the commented return).
return UIInterfaceOrientationMaskPortrait;
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
[super preferredInterfaceOrientationForPresentation];
// Return the orientation you'd prefer - this is what it launches to. The
// user can still rotate. You don't have to implement this method, in which
// case it launches in the current orientation
return UIInterfaceOrientationPortrait;
}
现在在 plist 文件中的更改下方执行此操作