gpt4 book ai didi

objective-c - 如何通过popoverview Controller 显示imagepickercontroller?

转载 作者:行者123 更新时间:2023-11-29 04:23:00 24 4
gpt4 key购买 nike

我使用以下代码从 iPhone 中的相册中获取照片,但它显示错误“UIImagePickerController 必须通过 UIPopoverController 呈现”

- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{

if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
[self setupImagePicker:sourceType];

[self presentModalViewController:imagePickerController animated:YES];

}
}


- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
imagePickerController.sourceType = sourceType;

if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
//
imagePickerController.showsCameraControls = NO;

if (imagePickerController.cameraOverlayView != self.view)
{
// setup our custom overlay view for the camera
//
// ensure that our custom view's frame fits within the parent frame
CGRect overlayViewFrame = imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,
CGRectGetHeight(overlayViewFrame) -
self.view.frame.size.height - 9.0,
CGRectGetWidth(overlayViewFrame),
self.view.frame.size.height + 9.0);
self.view.frame = newFrame;
imagePickerController.cameraOverlayView = self.view;
}
}
}



-(IBAction)getPhoto:(id)sender {
imagePickerController = [[UIImagePickerController alloc] init];
[self showImagePicker:UIImagePickerControllerSourceTypePhotoLibrary];
}

任何人都可以更改我的代码以在 iPad 上运行吗?提前致谢。

最佳答案

-(IBAction)Click_event {

UIImagePickerController *imagePickerController_=[[UIImagePickerController alloc] init];
UIPopoverController *popover_=[[UIPopoverController alloc] initWithContentViewController:imagePickerController_];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
imagePickerController_.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[popover_ presentPopoverFromRect:CGRectMake(400, 400, 0, 0) inView:self.Mybutton
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


}

}

关于objective-c - 如何通过popoverview Controller 显示imagepickercontroller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12726073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com