2

我已经阅读了几乎所有关于我的问题的帖子,但似乎没有一个解决方案适用于我的应用程序。

因此,我使用了从视图控制器模态呈现的自定义相机视图(带有工具栏上的按钮和叠加层)。我的应用程序仅支持横向左右方向的方向。我想阻止相机视图在呈现时自动旋转。我已将自动旋转所需的所有方法放在我的视图控制器和我的应用程序委托上。我也检查了我的 plist 文件,支持的旋转是正确的。但是当我旋转设备时,我的相机视图会继续旋转到任何旋转(纵向和横向),导致叠加层和工具栏的位置不正确。我也无法检查相机视图的方向,因为我尝试将 NSLog 放在 shouldAutoRotate 方法上,但它根本没有被调用。

那么如何检查自定义相机视图的旋转?我怎样才能强迫它不旋转并保持静止?

如果需要我的代码,我会在这里发布。如果有人可以帮助我,我将不胜感激,因为它现在让我非常沮丧。

谢谢你。干杯。

4

3 回答 3

2

创建一个新的“UIImagePickerController”类并在.m文件中实现给定的旋转委托,

// For lower iOS versions
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation  {

return ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || ((toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)));
}

// For iOS version 6.0 and above
- (BOOL)shouldAutorotate {

return YES;
}


- (NSUInteger)supportedInterfaceOrientations {

return (UIInterfaceOrientationMaskLandscape);
}

并创建一个让我们说 MyImagePickerController 而不是 UIImagePickerController 的实例,并呈现它。这将工作:)

于 2013-05-08T07:04:04.403 回答
0

xcode -> 文件 -> 新文件 在左侧窗格中选择 cocotouch 选择 Objective-c 类别 -> 下一个从下拉列表中选择UIImageImagePickerController上的名称Picker类别

进口

@interface UIImagePickerController(选择器)

-(BOOL) 应该自动旋转;-(NSUInteger)支持的接口方向;

@结尾

导入“UIImagePickerController+picker.h”

@implementation UIImagePickerController(选择器)

-(BOOL)应该自动旋转{

    return yourOrientation;

}

-(NSUInteger)supportedInterfaceOrientations {

    return yourInteger;

}

@结尾

在此之后,当您的设备的方向发生变化时,此时您必须从您的 UINavigationController 类别中调用 shouldAutoRotate 方法,如果是,则必须确定是否显示了 cameraview,然后您必须调用 Picker 的 shouldAutoRotate

见以下代码

在您的视图控制器的 shouldAutoRotate

-(BOOL)应该自动旋转{

   if([self presentingViewController])// Camera is present 
         return [instanceOfUIImagePickerController shouldAutoRotate];
   return yourOrientaionNeededForThisVC;

}

于 2013-05-08T09:04:32.373 回答
0

为UINavigationController创建一个类别

@interface UINavigationController(autoRotation)

-(BOOL)shouldAutoRotate;

@end

@implementation UINavigationController

-(BOOL)shouldAutoRotate{

  return [[self.viewControllers lastobject] shouldAutoRoatate];

}

-(NSUInteger)supportedInterfaceOrientations {

  return [[self.viewControllers lastobject] supportedInterfaceOrientations];

}

@end

在相应的视图控制器中实现这两种方法,并返回你真正想要的方向......

于 2013-05-08T05:38:01.007 回答