【问题标题】:Black Bar in UIImagePicker on iPad - Only in Landscape Right OrientationiPad 上 UIImagePicker 中的黑条 - 仅在横向右方向
【发布时间】:2012-01-15 09:30:51
【问题描述】:

我正在通过 UIPopOver 显示 UIImagePicker(它本身在 UIView 中)。这很好用,但是当 iPad 旋转到右侧时,我会在弹出框的左侧看到一个奇怪的黑条,如下图所示。取消按钮也部分位于屏幕右侧。这不会发生在任何其他奇怪的方向上。

代码也在下面列出。谁能建议我为什么会得到这个黑条?

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

    }

【问题讨论】:

    标签: objective-c xcode ipad uiimagepickercontroller uipopovercontroller


    【解决方案1】:

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

    要解决这个问题,请在您呈现弹出框之后设置框架(查看下面的代码)。

    这应该可以解决问题。

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

    另外,在您的控制器中,添加这个以在发生旋转时重置帧:

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    
        [imagePickerController.view setFrame:imagePickerController.view.superview.frame];
    }
    

    【讨论】:

      【解决方案2】:

      上述方法适用于 iOS 5 及更高版本,但在 iOS 4 及更早版本上,无法将 UIImagePickerController 添加为子视图然后显示它。它必须始终以 ModalViewController 的形式呈现。

      【讨论】:

        【解决方案3】:

        试试这个。重新发布我使用 [currentDevice endGeneratingDeviceOrientationNotifications] 找到的一种解决方案

        UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease]; 
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;  
        picker.delegate = self;
        
        // Display the camera.
        [self presentModalViewController:picker animated:YES];
        
        // Given by default your orientation is in landscape right already
        while ([currentDevice isGeneratingDeviceOrientationNotifications])
           [currentDevice endGeneratingDeviceOrientationNotifications];
        

        来源:Disable rotation in UIImagePicker

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-10-25
          • 1970-01-01
          • 2012-01-30
          • 2021-07-06
          • 2012-03-10
          • 1970-01-01
          • 1970-01-01
          • 2017-08-28
          相关资源
          最近更新 更多