Dav*_*ave 56 uiimagepickercontroller ipad ios ios8
是否有其他人UIImagePickerController在iOS 8中遇到问题?下面的方法在iPad上的iOS 7中运行得非常好,但是当我尝试呈现选择器(最后一行)时,我在XCode 6(Beta 3或4)中运行时会出现以下错误.如果重要,那么sourceType的选择来自于在同一个地方呈现的alertView.
Warning: Attempt to present <UIImagePickerController: 0x7c0ae400> on <CAGUCreateContactViewController: 0x7bf61a00> which is already presenting (null)
Run Code Online (Sandbox Code Playgroud)
打开imagePicker的方法.
- (void)openPhotoPicker:(UIImagePickerControllerSourceType)sourceType
{
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
if ([availableMediaTypes containsObject:(NSString *)kUTTypeImage]) {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
imagePickerController.sourceType = sourceType;
imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
imagePickerController.delegate = self;
self.imagePickerController = imagePickerController;
if (sourceType == UIImagePickerControllerSourceTypeCamera) {
[self presentViewController:self.imagePickerController animated:YES completion:nil];
} else {
if (self.popoverVC) {
[self.popoverVC dismissPopoverAnimated:YES];
self.popoverVC = nil;
}
self.popoverVC = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[self.popoverVC presentPopoverFromRect:self.nameAndPicCell.picture.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Ben*_*ngs 108
我认为这是因为在iOS 8中,警报视图和操作表实际上是视图控制器(UIAlertController).因此,如果您正在呈现一个新的视图控制器以响应来自该动作的动作UIAlertView,那么它将在UIAlertController被解雇时呈现.我通过延迟UIImagePickerController直到下一次runloop迭代的演示来解决这个问题,通过这样做:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self openPhotoPicker:sourceType];
}];
Run Code Online (Sandbox Code Playgroud)
但是,解决这个问题的正确方法是UIAlertController在iOS 8上使用新的API(即使用if ([UIAlertController class])...来测试它).如果您尚未使用新API,这只是一种解决方法.
ved*_*ano 80
我同意Ben Lings问题的检测.在使用UIActionSheet时,我会建议一个更简单的解决方案.我只是简单地移动了我的代码,该代码对Action Sheet选择起反应:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{
// my code
}
Run Code Online (Sandbox Code Playgroud)
成:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex; // after animation
{
// my code
}
Run Code Online (Sandbox Code Playgroud)
这样,应用程序可以保证在UIActionSheet动画完成后将执行代码.
由于UIAlertView具有类似的委托方法:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; // after animation
{
// my code
}
Run Code Online (Sandbox Code Playgroud)
我想类似的解决方案可能适用.
Tun*_*her 12
这是一个适合我的解决方案
if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0)
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentViewController:cameraUI animated:NO completion:nil];
}];
}
else{
[controller presentViewController:cameraUI animated:NO completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
记住分配 cameraUI
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
Run Code Online (Sandbox Code Playgroud)
建立和去!
我在iOS 8中遇到了同样的问题.然后我在设备上看到了iOS即8.0.2的最新更新的更改日志.
本次更新中提到_
"修复了导致某些应用无法访问照片库中的照片的问题"
因此,在iOS 8.0.2版本的设备上使用XCode 6测试您的应用程序它将正常工作不要在iOS 8.0模拟器上测试它.
这对我有所帮助,希望对你也一样.

| 归档时间: |
|
| 查看次数: |
30334 次 |
| 最近记录: |