1

iPhone で使用するとアプリがクラッシュしますが、 iOS 7UIImagePickerでのみ発生します。次のコード行を使用します

    picker = [[UIImagePickerController alloc] init];

    picker.delegate = self;
    picker.allowsEditing = YES;

    if( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
    {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    } else {
        //[self showAlertViewWithTitle:@"Sorry" message:@"Your Device Don't Have Camera"];
    }

    [self presentViewController:picker animated:YES completion:nil];

}

このアプリは iOS 7 ではなく iOS 6 で実行されています。このサイトは初めてです。助けてください。

4

3 に答える 3

1

@implementation を開始する前に、ViewController.m ファイルに次のコードを記述します。

@interface NonRotatingUIImagePickerController : UIImagePickerController

@end

@implementation NonRotatingUIImagePickerController

- (BOOL)shouldAutorotate
{
    return NO;
}

@end

Image Picker のオブジェクトを作成したい場所に以下のコードを書きます

UIImagePickerController* picker = [[NonRotatingUIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self; 
    [self presentModalViewController:picker animated:YES];
于 2013-10-21T06:46:45.740 に答える
1

iPhone のみのモードでのUIImagePickerControllerプレゼンテーション。そして、あなたが間違っている間Potratinに使用しているコードにもう1つのバグを見つけました:-picker.sourceType = UIImagePickerControllerSourceTypePhotoLibraryisCameraDeviceAvailable

次のようにコーディングする必要があります:-

if( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
    {
       picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                 [self presentViewController:picker animated:YES completion:nil];
    } else {
         picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                 [self presentViewController:picker animated:YES completion:nil];       
    }

そしてあなたの ViewControllershouldAutorotateに YES の代わりに NO に変更します

于 2013-10-21T06:34:43.637 に答える