2

I am making a camera app for iPad. I want the camera app to work only in portrait mode. I had to put in a rotation observation, and force the device to use portrait mode like this:

UIImagePickerController in Landscape

I think this is private API; some of the users on the post suggested that it is.

If so, what other work around can I use to force the overlay to stay in portrait mode only? If I don't add this code it rotates to both portrait and landscape mode.

    //Is this private?
    @interface UIDevice ()
    -(void)setOrientation:(UIDeviceOrientation)orientation;
    @end

    -(IBAction)InitiateCamera
    {

    overlayview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
    ...
    ...

    //monitor device rotation
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];




        //launch camera
        [self presentViewController:picpicker animated:YES completion:nil];


    }



    - (void) didRotate:(NSNotification *)notification
    {


//IS THIS PRIVATE?
        //Maintain the camera in portrait orientation
        [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }

    -(NSUInteger)supportedInterfaceOrientations
    {

        return UIInterfaceOrientationMaskPortrait;
    }

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }
Community
  • 1
  • 1
Sam B
  • 27,273
  • 15
  • 84
  • 121
  • I'm a little confused. I would have expected your `supportedInterfaceOrientations` method to prevent your UI from rotating to landscape orientations when this view controller was visible. It sounds like your interface is rotating anyway. Is that right? If you want the *entire app* to be portrait only, there's a key/value pair you can add to your target's Info.plist. – Aaron Golden Mar 02 '14 at 20:19
  • Trust me Aaron. That's exactly what I did and have done. First thing I did was set it in my plist file. Then I set it in code (as you can see above) yet for iPad for some reason it still likes to rotate in landscape. Hence my question of brute forcing it – Sam B Mar 02 '14 at 20:23
  • That's pretty weird. This is a silly thing, but may be worth a shot---try a clean build? Reset contents and settings in your simulator (or delete the app on your device) to make sure there's no stale Info.plist hanging around, and do a clean build/run from Xcode. I doubt that's it, but better to be sure. I really would have thought the `UISupportedInterfaceOrientations` in the Info.plist would be enough. – Aaron Golden Mar 02 '14 at 20:29

2 Answers2

8

Use this code instead. I submitted an app and it got approved on itunes

- (void) didRotate:(NSNotification *)notification
{
    [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];

}
Sam B
  • 27,273
  • 15
  • 84
  • 121
1

Yes it is. Though the orientation property appears in the UIDevice header, it's marked as readonly in that header.

Aaron Golden
  • 7,092
  • 1
  • 25
  • 31
  • Plus the fact that they had to create a category to define that symbol makes it pretty much everything but public API. – JustSid Mar 02 '14 at 20:14
  • I've edited the question to emphasize the search for alternatives; otherwise this is just "well, is it in the docs"? – jscs Mar 02 '14 at 20:14
  • what's the alternate to using? (void)setOrientation:? I have forced my app to use portrait mode and yet it still rotates in landscape. Hence my dilemma. – Sam B Mar 02 '14 at 20:16