ios – 在iphone模拟器上使用UIImagePickerController

前端之家收集整理的这篇文章主要介绍了ios – 在iphone模拟器上使用UIImagePickerController前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有方法,从画廊或相机拍照
-(IBAction) getPhoto:(id) sender {
  UIImagePickerController * picker = [[UIImagePickerController alloc] init];
  picker.delegate = self;

  if((UIButton *) sender == choosePhotoBtn) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
  } else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  }

  [self presentModalViewController:picker animated:YES];
}

但是当我在模拟器上运行它时,代码不起作用.并且它在picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum和picker.sourceType = UIImagePickerControllerSourceTypeCamera中不起作用

是模拟器还是代码中的问题?

解决方法

试试这个,
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
        {
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        }
        else
        {
            picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        }
        [self.navigationController presentModalViewController:picker animated:NO];

如果您要为iPad创建应用程序.您必须在popOver控件中显示库.

原文链接:https://www.f2er.com/iOS/329056.html

猜你在找的iOS相关文章