从 iPad 中的 UIActionSheet 为 uiimagepickercontrollersourcetypephotolibrary 显示 UIImagePickerViewControll
Posted
技术标签:
【中文标题】从 iPad 中的 UIActionSheet 为 uiimagepickercontrollersourcetypephotolibrary 显示 UIImagePickerViewController【英文标题】:Display UIImagePickerViewController for uiimagepickercontrollersourcetypephotolibrary from UIActionSheet in IPad 【发布时间】:2012-04-02 07:08:20 【问题描述】:我有一个UIActionSheet
,它可以选择从相机或照片库中选择图像。为此,我采用了 imagePickerViewController。对于相机,它工作得非常好。但不适用于照片库。
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
if (buttonIndex == 0)
imgController = [[UIImagePickerController alloc] init];
imgController.allowsEditing = YES;
imgController.sourceType = UIImagePickerControllerSourceTypeCamera;
imgController.delegate=self;
[self presentModalViewController:imgController animated:YES];
else if (buttonIndex == 1)
if ([self.popoverController isPopoverVisible])
[self.popoverController dismissPopoverAnimated:YES];
[popoverController release];
else
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = NO;
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
self.popoverController.delegate = self;
[self.popoverController setPopoverContentSize:CGSizeMake(500, 500)];
[self.popoverController presentPopoverFromRect:self.view.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[imagePicker release];
在触摸照片库选项时,会在视图顶部创建一个小的 popupViewController,但它非常小。为什么 popupViewController 太小了?有没有其他方法可以为uiimagepickercontrollersourcetypephotolibrary
显示UIImagePickerViewController
?
【问题讨论】:
根据需要更改 presentPopoverFromRect 大小 【参考方案1】:试试这个例子
CGRect popoverRect = [self.view convertRect:[self.view frame]
fromView:[self.view superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 80) ;
popoverRect.origin.x = popoverRect.origin.x+150;
[self.popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];
【讨论】:
【参考方案2】:尝试不要为弹出窗口中的UIImagePickerViewController
设置PopoverContentSize
- 我认为它会自动处理!此外,presentPopoverFromRect:
中的CGRect
似乎不正确,因为您正在传递view
的框架,该框架转换为大致指向屏幕中心的弹出框。您可能希望将其设置为显示 UIActionSheet
! 的按钮的框架!
【讨论】:
【参考方案3】:我认为你传入的rect应该更小,而不是整个视图的大小:
CGRect popFrom = CGRectMake (CGPointMake(50,50),10,10);
[self.popoverController presentPopoverFromRect:popFrom
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
【讨论】:
哈哈,深夜的错误,感谢您指出...我已经解决了,很高兴能帮到您:)【参考方案4】:试试这个:
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePickerController animated:YES];
【讨论】:
以上是关于从 iPad 中的 UIActionSheet 为 uiimagepickercontrollersourcetypephotolibrary 显示 UIImagePickerViewControll的主要内容,如果未能解决你的问题,请参考以下文章
iPad 上 UIPopoverController 中 UIActionSheet 的自定义背景
iPad 崩溃并从子视图控制器显示 UIActionSheet
在 iPad 的 UIActionSheet 中添加 UIPickerView