有很多关于如何添加按钮以从相机 View 访问照片库的示例,但我似乎找不到任何关于这样做的其他方法。
在我的应用程序中,图像的主要来源是库,但如果用户真的愿意,我也想让他们使用相机。如果可能的话,我想避免额外的步骤,即展示带有两个选项(库和相机)或一些类似解决方案的操作表。另外,我不希望有两个专用按钮。
最佳答案
我使用这段代码:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
self.imgPicker = [[UIImagePickerController alloc] init];
if(buttonIndex == 0) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
self.imgPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
}
}
if(buttonIndex == 1) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
}
}
[self performSelector:@selector(showPicker) withObject:self afterDelay:0.6f];
}
- (void)showPicker {
[self presentModalViewController:self.imgPicker animated:YES];
}
关于ios - 使用 UIImagePickerController 从照片库中访问相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23321980/