简体   繁体   English

IOS7 Xcode 5通用应用程序不会在iPhone上旋转,但会在iPad上旋转

[英]IOS7 Xcode 5 universal app won't rotate on iphone, but will on ipad

I have and app that was initially built for ipad and i'm in the midst of making it a universal app. 我拥有一个最初为ipad打造的应用程序,并且我正在使其成为通用应用程序。 I've got the entire app working, universally, all functionality is working and sized correctly. 总的来说,我已经使整个应用程序正常工作,所有功能都在正常工作并且大小正确。 Except that on the iphone the app won't rotate in any direction, it stays in portrait mode. 除了在iPhone上,该应用不会向任何方向旋转外,它始终处于纵向模式。

Here's what i've got: 这是我所拥有的:

  • Checked the iPhone Device Orientation from the Targets/General section: (Portrait, Landscape Left and Landscape Right) are all checked 从“目标/常规”部分检查了“ iPhone设备方向” :(纵向,左横向和右横向)都已选中
  • In my Main_iPhone.storyboard i have a root view controller attached to a uinavigation controller that pops a settings (uitableview) upon the first load of the app. 在我的Main_iPhone.storyboard中,我有一个连接到uinavigation控制器的根视图控制器,该控制器会在应用程序首次加载时弹出设置(uitableview)。 (same as the ipad story board but sized for iphone) (与ipad故事板相同,但大小适合iphone)
  • the view controller programatically loads a xib: TakePhotoView.xib to a cameraOverlayView which has a label on it to tell the user to touch the screen to take a picture. 视图控制器以编程方式将xib:TakePhotoView.xib加载到cameraOverlayView上,该相机上有一个标签,告诉用户触摸屏幕进行拍照。

Again, this works perfect on the ipad and i'm very new to ios development. 再次,这在ipad上非常完美,我对ios开发还是很陌生。 i Actually had a friend develop the ipad app and i;m using it as my step-off point to dig into ios, thus i'm trying to turn it into a universal app to get my feet wet. 我实际上有一个朋友开发了ipad应用程序,我将其用作深入研究ios的出发点,因此,我试图将其转变为通用应用程序,以使我的脚浸湿。

Any pointers would be much appreciated. 任何指针将不胜感激。 I'm pulling my hair out with this. 我正在用这个拔头发。

 (BOOL) shouldAutorotate{
    return YES;
}
- (NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight; //you can choose either landscape orientation here
}

Finally got this figured out. 终于弄明白了。 It was the UIImagePickerController. 它是UIImagePickerController。 For some reason it worked perfect for the ipad but i needed to overwrite it for the iphone. 由于某种原因,它对于ipad来说非常完美,但是我需要为iphone覆盖它。

#import "UIImagePickerController+rotation.h"

@interface UIImagePickerController (private)

- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
- (NSUInteger)supportedInterfaceOrientations;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

@end


@implementation UIImagePickerController (Private)

- (NSUInteger)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskAll;
}

- (BOOL)shouldAutorotate {

    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        return UIInterfaceOrientationPortrait;
    }
    else
    {
        return UIInterfaceOrientationLandscapeRight;
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
@end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM