iPad上的UIImagePicker中的黑条 - 仅在横向右方位 [英] Black Bar in UIImagePicker on iPad - Only in Landscape Right Orientation

查看:119
本文介绍了iPad上的UIImagePicker中的黑条 - 仅在横向右方位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过UIPopOver显示UIImagePicker(本身在UIView中)。这样可以正常工作,但是当iPad旋转到右侧时,我会在弹出框的左侧看到一个奇怪的黑条,如下图所示。取消按钮也部分偏离屏幕右侧。在任何其他奇怪的方向都不会发生这种情况。

I am showing a UIImagePicker (itself in a UIView) via a UIPopOver. This works fine, however when the iPad is rotated onto its right side I get a strange black bar along the left hand side of the popover as per the image below. The cancel button is also partially off the right hand of the screen. This doesn't happen in any other orientation which is odd.

下面还列出了代码。任何人都可以建议我为什么得到这个黑条?

The code is also listed below. Can anyone suggest why I am getting this black bar ?

imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);

UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(width, height);
[imagePickerController.view setFrame:containerController.view.frame];
[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];

        [containerController release];

    }

推荐答案

出于某种奇怪的原因,视图的框架确实发生了变化在横向右侧。

For some strange reason, the view's frame does change in landscape right.

为了解决这个问题,请在之后设置框架,以显示弹出窗口(查看下面的代码)。

To come over this, set the frame after you present the popover (view code below).

这应该可以解决问题。

imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);

UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(width, height);

[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];

        [containerController release];

    }

此外,在您的控制器中,添加此项以重置帧当旋转发生时:

Also, in your controller, add this to reset the frames when the rotation occurs:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {

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

这篇关于iPad上的UIImagePicker中的黑条 - 仅在横向右方位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆