仅支持iOS 6的一个视图的不同方向

Ale*_*x G 29 xcode objective-c ios

我想在我的应用程序中仅旋转我的一个视图,无论是横向左侧还是横向右侧.我的所有其他视图都处于纵向模式,我已将我的应用程序设置为仅支持纵向模式.在iOS 6中改变方向,我不知道如何做到这一点.我试过下面发布的以下内容.谁能告诉我我做错了什么?谢谢!

-(BOOL)shouldAutorotate {
return YES;
}

-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
} 
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didRotate:)
                                            name:UIDeviceOrientationDidChangeNotification
                                           object:nil];
return YES;//UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
} 


 -(void)didRotate:(NSNotification *)notification {
 UIDeviceOrientation orientation = [[notification object] orientation];

if (orientation == UIDeviceOrientationLandscapeLeft) {
    [theImage setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
    [self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
} else if (orientation == UIDeviceOrientationLandscapeRight) {
    [theImage setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
    [self.view setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
    [theImage setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
    [self.view setTransform:CGAffineTransformMakeRotation(M_PI / -2.0)];
} else if (orientation == UIDeviceOrientationPortrait) {
    [theImage setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
    [self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2.0)];
}
}
Run Code Online (Sandbox Code Playgroud)

Cha*_*irA 19

这对我有用如何在iOS 6中强制UIViewController到Portrait方向

从UINavigationController创建一个新类别,覆盖旋转方法:

-(BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

@end 
Run Code Online (Sandbox Code Playgroud)


Nek*_*kto 6

iOS 6中有关于处理视图旋转的更改.Info.plist支持在应用中定义的方向.即使你要归还其他人.

尝试选择项目中支持的所有方向.

处理视图旋转

在iOS 6中,您的应用程序支持应用程序Info.plist文件中定义的界面方向.视图控制器可以覆盖该supportedInterfaceOrientations方法以限制支持的方向列表.通常,系统仅在窗口的根视图控制器或呈现的视图控制器上调用此方法以填充整个屏幕; 子视图控制器使用由父视图控制器为其提供的窗口部分,不再直接参与有关支持哪些旋转的决策.应用程序的方向遮罩和视图控制器的方向遮罩的交点用于确定视图控制器可以旋转到哪个方向.

您可以覆盖preferredInterfaceOrientationForPresentation打算以特定方向全屏显示的视图控制器.

在iOS 5及更早版本中,UIViewController该类仅以纵向模式显示视图.要支持其他方向,必须覆盖该shouldAutorotateToInterfaceOrientation:方法,并为子类支持的任何方向返回YES.如果正确配置了视图的自动调整属性,则可能只需要执行此操作.但是,UIViewController该类为您提供了额外的挂钩,以根据需要实现其他行为.通常,如果您的视图控制器旨在用作子视图控制器,它应该支持所有接口方向.

当可见视图控制器发生旋转时,在旋转期间会调用willRotateToInterfaceOrientation:duration:willAnimateRotationToInterfaceOrientation:duration:,和didRotateFromInterfaceOrientation:方法.在viewWillLayoutSubviews调整视图大小并由其父视图定位视图后,也会调用该方法.如果在发生方向更改时视图控制器不可见,则永远不会调用旋转方法.但是,viewWillLayoutSubviews当视图变为可见时,将调用该方法.您对此方法的实现可以调用该statusBarOrientation方法来确定设备方向.

(C)Apple Docs:UIViewController