2016-09-06 9 views
0

私は風景モードで保存したいビューコントローラを持っています。クラスに次のコードを追加しました:iOS:画像ピッカーをキャンセルした後に向きがポートレートに変わる

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask 
    { 
     return UIInterfaceOrientationMask.Landscape 
    } 

    func navigationControllerSupportedInterfaceOrientations(navigationController: UINavigationController) -> UIInterfaceOrientationMask 
    { 
     return UIInterfaceOrientationMask.Landscape 
    } 

    override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation 
    { 
     return UIInterfaceOrientation.LandscapeLeft 
    } 

私はUIImagePickerControllerを開いて写真を選択します。ピッカーで[キャンセル]をクリックすると、アプリはポートレートモードで自分のView Controllerに戻ります。

UIDevice.currentDevice().setValue(orientationBeforeShowingImagePicker.rawValue, forKey: "orientation") 

答えて

0
Finally. This worked for me. 

@try 
{ 
    // Create a UIImagePicker in camera mode. 
    UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease]; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    picker.delegate = self; 

    // Prevent the image picker learning about orientation changes by preventing the device from reporting them. 
    UIDevice *currentDevice = [UIDevice currentDevice]; 

    // The device keeps count `enter code here`of orientation requests. If the count is more than one, it continues detecting them and sending notifications. So, switch them off repeatedly until the count reaches zero and they are genuinely off. 
    // If orientation notifications are on when the view is presented, it may slide on in landscape mode even if the app is entirely portrait. 
    // If other parts of the app require orientation notifications, the number "end" messages sent should be counted. An equal number of "begin" messages should be sent after the image picker ends. 
    while ([currentDevice isGeneratingDeviceOrientationNotifications]) 
     [currentDevice endGeneratingDeviceOrientationNotifications]; 

    // Display the camera. 
    [self presentModalViewController:picker animated:YES]; 

    // The UIImagePickerController switches on notifications AGAIN when it is presented, so switch them off again. 
    while ([currentDevice isGeneratingDeviceOrientationNotifications]) 
     [currentDevice endGeneratingDeviceOrientationNotifications]; 
} 
@catch (NSException *exception) 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Camera" message:@"Camera is not available" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 
:私はまた、初回のみのために働くことで、私のコントローラに戻って行くときの方向を設定してみました
関連する問題