2014-05-06 42 views
0

我有一个处于横向模式的应用程序。iPhone/iPad中的方向问题

该应用程序专为iPhone和iPad设计。

我正在打开照片库,从那里访问照片,并从我的一些视图中捕捉照片。

但据我所知,照片库只能在肖像模式下打开,所以我从下面显示的设置中选择所有的方向。

enter image description here

我也做了同样的事情iPad也。

所以我尝试从所有视图的代码。

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

因此,所有的视图只能在肖像模式下锁定。

但我的看法仍然显示在肖像模式也。

对于图片库,我做了一个不同的类,如下所示。

@interface NonRotatingUIImagePickerController8 : UIImagePickerController 

@end 

@implementation NonRotatingUIImagePickerController 



- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait ; 
} 

@end 



@interface NonRotatingUIImagePickerController2 : UIImagePickerController 

@end 

@implementation NonRotatingUIImagePickerController2 

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

@end 

因此,我的照片库以纵向模式显示,但我的所有其他视图以纵向模式显示。

那么我该如何解决这个问题?

请帮帮我。

卡住了很长一段时间。

在此先感谢....

**Edited** 

enter image description here

如果我做这样我的应用充分说明在风景模式,但是当我尝试打开照片库崩溃。

我该怎么做?

请帮忙....

+0

所以我的照片库中显示POTRAIT模式但我的所有其他视图以POTRAIT模式显示。你什么意思?错字?如果可以的话,上传一个示例项目到Github并链接到这里,有人可以为你解决这个问题。 – Ricky

+0

如果我没有从我的项目设置中选择肖像,如图中所示,那么我的应用程序将崩溃,因为照片库只能在iPhone的肖像模式下打开... – Manthan

+0

self.view.transform = CGAffineTransformMakeRotation(M_PI_2) ;在你的照片库视图中使用 –

回答

1

我也遇到过这种情况,我找到了解决办法,看看我下面的代码。

首先评论您在每个班级中编写的所有方向方法。

然后对号所有orientaition像下面

enter image description here

现在

在AppDelegate中。下面的代码在“呈现” M文件写入是的UIViewController在你试图打开pickerview

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    NSUInteger orientations = UIInterfaceOrientationMaskAll; 

    if (self.window.rootViewController) { 
     UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject]; 
     if([presented isKindOfClass:[PhotoVC class]]) 
     { 
      orientations = [presented supportedInterfaceOrientations]; 
      return orientations; 
     } 
     orientations = UIInterfaceOrientationMaskLandscape; 
    } 
    return orientations; 
} 

现在我的代码替换代码在你NonRotatingUIImagePickerController2像下面

@interface NonRotatingUIImagePickerController2 : UIImagePickerController 

@end 

@implementation NonRotatingUIImagePickerController2 

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskLandscape; 
} 


@end 

请检查并让我知道它工作与否!

快乐编码!在方向下拉

打开你的故事板,选择视图控制器,然后选择“风景”:

+0

因为NavigationController的问题? – Manthan

+0

没有问题不是因为NavigationController,你错过了我的朋友,你是否从所有的视图控制器中删除所有的方向代码? – NiravPatel

+0

是的,我做了,但我发现了另一个解决方案https://github.com/B-Sides/ELCImagePickerController/tree/master/Classes/ELCImagePicker,它以横向模式打开ImagePicker。非常感谢您的帮助,直到现在。我将保留你的代码并将其用于将来的项目,因为现在我正在对旧项目进行更改,所以问题就在于此,因为我对前一个开发人员的代码没有多少了解。我只是对现有项目进行一些修改。 – Manthan