简体   繁体   中英

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. 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.

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
  • 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. (same as the ipad story board but sized for 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.

Again, this works perfect on the ipad and i'm very new to ios development. 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.

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. For some reason it worked perfect for the ipad but i needed to overwrite it for the 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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