使用objective-c以编程方式颠倒iOS应用程序

使用objective-c以编程方式颠倒iOS应用程序,ios,objective-c,uiinterfaceorientation,portrait,Ios,Objective C,Uiinterfaceorientation,Portrait,我想在ViewController中使用以下代码将我的应用程序上下颠倒: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { //return NO; // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationMask

我想在ViewController中使用以下代码将我的应用程序上下颠倒:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{    //return NO;
  // Return YES for supported orientations
  return (interfaceOrientation == UIInterfaceOrientationMaskPortraitUpsideDown);
}


- (UIInterfaceOrientationMask) supportedInterfaceOrientations

{
  return [super supportedInterfaceOrientations] | UIInterfaceOrientationMaskPortraitUpsideDown | UIInterfaceOrientationMaskPortrait;
}
在AppDelegate中:

- (UIInterfaceOrientationMask) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{
  return UIInterfaceOrientationMaskPortraitUpsideDown | UIInterfaceOrientationMaskPortrait;
}
当用户按下按钮时

NSNumber * value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
  [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
该应用程序不知何故没有旋转,我也不知道为什么。 有人能给点提示吗? 非常感谢。
我在info.plist中添加了方向,并在deployment info部分的general settings(常规设置)中设置了复选框。

我是否正确理解您的意思,您希望以编程方式旋转用户界面,而不依赖于设备的物理方向

这不是它的工作方式:当检测到设备(物理)旋转时,iOS会调用委托方法(shouldAutorotate…等),例如,用户将其倒置。在委托方法中,如果需要的话,您就有机会采用新方向的视图


在模拟器中,您可以通过Alt+Left/Alt+Right键模拟设备旋转。

我是否正确理解您的意思,您希望通过编程方式旋转用户界面,而不依赖于设备的物理方向

这不是它的工作方式:当检测到设备(物理)旋转时,iOS会调用委托方法(shouldAutorotate…等),例如,用户将其倒置。在委托方法中,如果需要的话,您就有机会采用新方向的视图


在模拟器中,您可以通过Alt+Left/Alt+Right键模拟设备旋转。

您无法通过编程方式旋转方向,这取决于设备的传感器。但是,可以旋转视图的图层

self.view.layer.transform = CGAffineTransformMakeRotation(M_PI_2);

无法通过编程方式旋转方向,这取决于设备的传感器。但是,可以旋转视图的图层

self.view.layer.transform = CGAffineTransformMakeRotation(M_PI_2);

您的应用程序是否有导航控制器?是的,有。为什么?你的应用程序有导航控制器吗?有。为什么?嗨,不,事实上我希望用户旋转设备本身,应用程序也应该旋转-否则一切都会颠倒过来,对吗?嗨,不,事实上我希望用户旋转设备本身,应用程序也应该旋转-否则一切都会颠倒过来,对吗?这很奇怪,因为方向改变在应用程序中起作用,我只有一个视图-我不知道问题是否与拥有多个视图控制器有关这很奇怪,因为方向改变在应用程序中起作用,我只有一个视图-我不知道问题是否与拥有多个视图控制器有关