4

カメラ機能を備えたアプリを作成しようとしていますが、オーバーレイビューを使用して画像で装飾しています。

これが私がアプリを実装する方法です:私はUIImagePickerControllerを使用して、カメラが取り込むものをユーザーに提供し、UIImageViewをサブビューとしてcameraOverlayViewに追加して、次のように機能させます:
http://www.manna-の画像soft.com/test/uploads/UIImagePickerView-portrait.jpg

これは、iPad2が所定の位置に配置されるまで正常に機能します...このように自動回転し、レイアウトを台無しにします:
http://www.manna-soft.com/test/uploads/UIImagePickerView-landscape.jpgの画像)

UIImagePickerControllerは、iphone、ipod touch、または元のiPadでは回転しませんが、iPad2では回転します。UIImagePickerContrllerのクラスリファレンスには、「ポートレートモードのみをサポートする」と記載されていますが、そのように自動回転するとどうなりますか。自動回転
を無効にする方法はありますか?
UIImagePickerControllerが表示されるビューコントローラーのshouldAutorotateToInterfaceOrientation:メソッドでNOを返そうとしましたが、それでも回転します。

前もって感謝します。

4

4 に答える 4

5

オーバーレイ ビューをウィンドウに追加し、window.superview を cameraOverlayView として設定できます。ModalController を閉じるときに、オーバーレイ ビューをウィンドウから削除できます。

アプリの構造によっては、このソリューションを適用するのが少し難しい場合があります。

YourAppDelegate *appDelegate = (YourAppDelegate *) [[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview:overlayView];
imagePickerController.cameraOverlayView = appDelegate.window.superview;


//When dismissing the UIImagePicker
 [self dismissModalViewControllerAnimated:YES];
 [OverlayView removeFromSuperview]; 
于 2011-04-25T14:37:15.650 に答える
0

UIImagePickerController は、UIViewController から派生した UINavigationController から派生しているため、UIViewController ドキュメントの「Handling View Rotations」でチェックアウトして、その情報が役立つかどうかを確認できます。

于 2011-04-18T08:50:26.233 に答える
-3

UIImagePickerController のオーバーレイ ビューを回転させることで、iPad の回転を補正できます。まず、次を使用して通知をキャプチャする必要があります。

[[NSNotificationCenter defaultCenter]     addObserver:self selector:@selector(notificationCallback:) name:nil object:nil];

次に、次のコードを使用します。

 - (void) notificationCallback:(NSNotification *) notification {
  if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    if ([[notification name] isEqualToString:@"UIDeviceOrientationDidChangeNotification"]) { 

        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

        switch ( orientation ) {
            case UIInterfaceOrientationLandscapeRight:
                NSLog(@"LandcapeRight");
                [UIView beginAnimations:@"LandscapeRight" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformIdentity;
                [UIView commitAnimations];
                break;
            case UIInterfaceOrientationLandscapeLeft:
                NSLog(@"LandscapeLeft");
                [UIView beginAnimations:@"LandcapeLeft" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(M_PI), 0, 0);
                [UIView commitAnimations];
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                NSLog(@"UpsideDown");
                [UIView beginAnimations:@"UpsideDown" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(-M_PI / 2), -128, -128);
                [UIView commitAnimations];
                break;
            case UIInterfaceOrientationPortrait:
                NSLog(@"Portrait");
                [UIView beginAnimations:@"Portrait" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(M_PI / 2), 128, 128);
                [UIView commitAnimations];
                break;
            default:
                NSLog(@"????");
                break;
        }
    }
 }
}
于 2011-04-25T08:50:18.020 に答える