由于ShouldAutorotateToInterfaceOrientation在iOS 6中已弃用并且我使用它来强制特定视图仅限于纵向,在iOS 6中执行此操作的正确方法是什么?这仅适用于我的应用的一个区域,所有其他视图都可以旋转.
我想在我的应用程序中仅旋转我的一个视图,无论是横向左侧还是横向右侧.我的所有其他视图都处于纵向模式,我已将我的应用程序设置为仅支持纵向模式.在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 == …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我仅在其目标设置中将方向设置为纵向:
在一个特定的视图控制器中,我想覆盖此设置,以便在设备旋转时自动布局将更新视图。我试过这些方法没有成功:
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.AllButUpsideDown
}
Run Code Online (Sandbox Code Playgroud)