gpt4 book ai didi

objective-c - 更改通过 UIPopOver (iPad) 呈现的 UIImagePicker 的大小

转载 作者:太空狗 更新时间:2023-10-30 03:59:02 24 4
gpt4 key购买 nike

我正在尝试更改通过 UIPopOver 呈现的 UIImagePicker 的大小。代码如下所示。问题是 PopOver 大小无法正确显示 - 它会以正确的大小短暂闪烁,然后以动画方式缩小到通常的默认大小。

谁能告诉我如何更改弹出窗口的大小?

- (void)showImagePickerForPhotoLibrary {
NSLog(@"Picker");
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.contentSizeForViewInPopover = CGSizeMake(768, 1000);

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(@"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
//popoverController.popoverContentSize = CGSizeMake(768, 1000);
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
}
}
else {
[app.mainViewController presentModalViewController:imagePickerController animated:YES];
}
}

最佳答案

我不确定这是最优雅的解决方案,但它对我来说似乎工作正常:

您可以将 UIImagePickerController 的 View 嵌入到“容器”UIViewController 的 View 中。

- (void)showImagePickerForPhotoLibrary {
NSLog(@"Picker");
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(768, 1000);

[containerController.view addSubview:imagePickerController.view];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(@"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];

[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];


[imagePickerController.view setFrame:containerController.view.frame];
}
}
else {
[app.mainViewController presentModalViewController:containerController animated:YES];
}
}

希望对你有帮助

编辑:由于某些奇怪的原因,当横向正确时,框架确实发生了变化。

要解决这个问题,您需要在显示弹出窗口后设置图像选择器的 View 框架。

我已经编辑了上面的代码以显示这一点。

此外,在您的 Controller 中,添加以下内容:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

[imagePickerController.view setFrame:imagePickerController.view.superview.frame];
}

关于objective-c - 更改通过 UIPopOver (iPad) 呈现的 UIImagePicker 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8418024/

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