Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 通过UIPopOver(iPad)更改UIImagePicker的大小_Objective C_Ipad_Uiimagepickercontroller_Uipopovercontroller - Fatal编程技术网

Objective c 通过UIPopOver(iPad)更改UIImagePicker的大小

Objective c 通过UIPopOver(iPad)更改UIImagePicker的大小,objective-c,ipad,uiimagepickercontroller,uipopovercontroller,Objective C,Ipad,Uiimagepickercontroller,Uipopovercontroller,我正在尝试更改通过UIPopOver呈现的UIImagePicker的大小。代码如下所示。问题是PopOver的大小显示不正确-它会以正确的大小短暂闪烁,然后以通常的默认大小设置动画 有人能告诉我怎样才能改变府绸的尺寸吗 - (void)showImagePickerForPhotoLibrary { NSLog(@"Picker"); imagePickerController = [[UIImagePickerController alloc] init]; imag

我正在尝试更改通过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的视图嵌入到“容器”UIViewController的视图中

- (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];
    }   
}
希望这有帮助

编辑:由于一些奇怪的原因,当处于横向时,帧确实会发生变化

为了解决这个问题,您需要在呈现popover之后设置图像选择器视图的帧

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

此外,在控制器中,添加以下内容:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

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

当我尝试Mutix的解决方案时,popover只显示了导航栏和一个空白的白色视图

我的解决方法是将imagePickerController添加为containerController的子级,而不仅仅是添加picker的视图

- (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];
    }   
}
主要是指更换这条线路:

[containerController.view addSubview:imagePickerController.view];
以下几行:

[containerController addChildViewController:imagePickerController];
[containerController.view addSubview:imagePickerController.view];
[imagePickerController didMoveToParentViewController:containerController];

此外,在使用这种方法时,我不需要对横向模式进行任何特殊处理。

谢谢。我是否可以得到line Container Controller的iPad的宽度和高度。contentSizeForViewInPopover=CGSizeMake(768,1000)?ipad的分辨率为768x1024。如果您希望popover占据整个屏幕,请尝试CGSizeMake(self.view.frame.size.width,self.view.frame.size.height)这种功能,但会导致另一个(奇怪的)错误: