私有的替代 - [UIDevice setOrientation:]用于强制相机覆盖进入纵向模式

Sam*_*m B 2 cocoa-touch objective-c ios

我正在为iPad制作相机应用程序.我希望相机应用程序仅在纵向模式下工作.我不得不进行旋转观察,并强制设备使用纵向模式,如下所示:

Landscape中的UIImagePickerController

我认为这是私有API; 帖子上的一些用户建议它是.

如果是这样,我可以使用哪些其他工作来强制叠加层仅保持纵向模式?如果我不添加此代码,它将旋转为纵向和横向模式.

    //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;
    }
Run Code Online (Sandbox Code Playgroud)

Sam*_*m B 8

请改用此代码.我提交了一个应用程序并获得了itunes的批准

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

}
Run Code Online (Sandbox Code Playgroud)