2013-05-08 111 views
1

我已经阅读了几乎所有关于我的问题的文章,但没有一个解决方案似乎适用于我的应用。在iOS 6.1中自定义自定义相机视图

因此,我使用自定义的相机视图(带有工具栏和覆盖图上的按钮),这是从视图控制器以模态方式呈现的。我的应用只支持横向左右方向。我想在自动旋转时停止相机视图。我已经将所有自动旋转所需的方法放到了我的视图控制器和我的应用程序委托中。我也检查过我的plist文件,支持的旋转是正确的。但是当我旋转设备时,我的相机视图会一直旋转到任何旋转(纵向和横向),导致覆盖层和工具栏被错误定位。我也无法检查相机视图的方向,因为我试图把NSLog放在shouldAutoRotate方法上,但它根本不会被调用。

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

如果我的代码是需要的,我会在这里发布。如果任何人都可以帮助我,我会非常感激,因为它现在让我非常失望。

谢谢。干杯。

+0

您的项目有导航控制器? – 2013-05-08 04:31:12

+0

是的,我使用导航控制器 – tyegah123 2013-05-08 04:45:04

+0

好吧,我认为现在唯一的解决方法就是使用iPad本身的按钮来锁定自动旋转。 – tyegah123 2013-05-08 05:19:24

回答

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,并呈现它。这将工作:)

+0

谢谢你的回答。我现在正在尝试这个,我会让你知道它是否工作:) – tyegah123 2013-05-08 07:44:00

+0

男人,非常感谢你。它运作良好。已经接受你的答案。 :) – tyegah123 2013-05-08 07:49:10

+0

欢迎:) – 2013-05-08 09:11:32

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 

在相应的视图控制器 实现这两个方法,并返回什么ü真正想要的方向....

+0

谢谢您的回答。但我也已经尝试过这种方法。没有给我我想要的结果。但也许我错过了一些东西。所以,也许我会尝试更多的这种方法。 – tyegah123 2013-05-08 05:54:21

+0

你如何带上你的相机?使用presentModalViewController?如果是,您的UIImagePickerViewController不存在于导航堆栈中。所以你必须为你的IMagePickerViewController创建一个类别并且调用shouldAutoRotae ... – jailani 2013-05-08 06:16:56

+0

是的,我正在使用presentModalViewController。你能给我示例代码来创建类别吗?我一定会尝试一下,因为它看起来像是这样。 – tyegah123 2013-05-08 07:37:34

0

的Xcode - >文件 - >在leftpane新文件选择cocotouch选择的Objective-C类 - >未来 从下拉式

进口

给出名称选择器类UIImageImagePickerController

@interface的UIImagePickerController(拾取器)

- (BOOL)shouldAutoRotate; - (NSUInteger)supportedInterfaceOrientations;

@end

进口“的UIImagePickerController +选择器。H”

@implementation的UIImagePickerController(拾取器)

- (BOOL)shouldAutoRotate {

return yourOrientation; 

}

- (NSUInteger)supportedInterfaceOrientations {

return yourInteger; 

}

@end

这时候你的设备的方向则改变了方法shouldAutoRotate获得从此时您的UINavigationController类叫你必须找出是否cameraview提出,如果是,那么你必须调用选择器

的shouldAutoRotate后

请看下面的代码

在您的视图控制器的shouldAutoRotate

- (BOOL)shouldAutoRotate {

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

}