1

ビデオを録画するための UIButton を表示するビューを使用して、viewcontroller をユーザーに提示します。ユーザーがボタンを押すと、次のエラーでアプリがクラッシュします。

キャッチされない例外 'UIApplicationInvalidInterfaceOrientation' が原因でアプリを終了しています。理由: 'preferredInterfaceOrientationForPresentation は、サポートされているインターフェイスの向きを返す必要があります!'

私のアプリは縦向きのみをサポートし、info.plist ファイルは正しく反映されます。Ray Wenderlich のサイトにある別のアプリで同じコードを使用していますが、うまく機能します。.h および .m ファイルのコードは次のとおりです。どんな助けでも大歓迎です。

.h

#import <MediaPlayer/MediaPlayer.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import <AssetsLibrary/AssetsLibrary.h>

@interface RecordSwingViewController: UIViewController

-(BOOL)startCameraControllerFromViewController:(UIViewController*)controller
                                 usingDelegate:(id )delegate;
-(void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void*)contextInfo;



@property (weak, nonatomic) IBOutlet UIButton *record;
- (IBAction)recordSwing:(id)sender;

@end

.m

#import "RecordSwingViewController.h"

@interface RecordSwingViewController ()

@end

@implementation RecordSwingViewController



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)recordSwing:(id)sender {
    [self startCameraControllerFromViewController:self usingDelegate:self];

}
-(BOOL)shouldAutorotate
{
    return NO;
}



-(BOOL)startCameraControllerFromViewController:(UIViewController*)controller
                                 usingDelegate:(id )delegate {
    // 1 - Validattions
    if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
        || (delegate == nil)
        || (controller == nil)) {
        return NO;
    }
    // 2 - Get image picker
    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
    cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
    // Displays a control that allows the user to choose movie capture
    cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
    // Hides the controls for moving & scaling pictures, or for
    // trimming movies. To instead show the controls, use YES.
    cameraUI.allowsEditing = NO;
    cameraUI.delegate = delegate;
    // 3 - Display image picker
    [controller presentViewController: cameraUI animated: YES completion:nil];
    return YES;
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    [self dismissViewControllerAnimated:NO completion:nil];
    // Handle a movie capture
    if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
        NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)) {
            UISaveVideoAtPathToSavedPhotosAlbum(moviePath, self,
                                                @selector(video:didFinishSavingWithError:contextInfo:), nil);
        }
    }
}

-(void)video:(NSString*)videoPath didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo {
    if (error) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Video Saving Failed"
                                                       delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Video Saved" message:@"Saved To Photo Album"
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}
@end
4

2 に答える 2

1

わかりました、ここに答えがあります。
https://stackoverflow.com/a/12570501/2133494 基本的に、UIImagePickerController にカテゴリを追加する必要がありました。他の多くの修正を試みましたが、これはうまくいきました。

于 2013-03-10T17:39:04.207 に答える
0

自動回転用の bool を実装しましたが、自動回転しない場合は他に何をすべきかを指定していません。autorotate メソッドの後に次のことを試してください。

 -(NSUInteger)supportedInterfaceOrientations
 {
 return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft   | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
 }

上記の方法から不要なマスクを削除し、これが機能するかどうかを確認してください.

于 2013-03-05T22:55:44.397 に答える