【问题标题】:UIImagePickerController in UIPopOverController is not opening up in iOS 5UIPopOverController 中的 UIImagePickerController 未在 iOS 5 中打开
【发布时间】:2011-11-22 05:13:53
【问题描述】:

在我的 iPad 应用程序中,我在弹出框控制器中打开照片库。它在 iOS 4 中运行良好,但现在在 iOS 5 中无法打开。 我正在使用以下代码打开照片库,

UIImagePickerController* picker = [[UIImagePickerController alloc] init]; 
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

    popOver = [[UIPopoverController alloc] initWithContentViewController:picker]; 
    popOver.delegate = self;

    int w = 320;

    CGRect pickerFrame = CGRectMake(0, 0, w, bImportPicker.frame.origin.y);
    [popOver setPopoverContentSize:pickerFrame.size animated:NO];   
    [popOver presentPopoverFromRect:pickerFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
    [picker release];

【问题讨论】:

    标签: ipad ios5 uiimagepickercontroller uipopovercontroller


    【解决方案1】:

    在我的代码中,我有一个 UIImageView,每当我点击它时,带有来自 iPhone 库的图像的 PickerView 就会在 PopOverController 中打开。

      UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    
       [myImageView addGestureRecognizer:singleTap];   // added action for SingleTap
    
    
    
    
      - (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {  
    // single tap does nothing for now  
    
        if ([UIImagePickerController isSourceTypeAvailable: 
                    UIImagePickerControllerSourceTypePhotoLibrary]) 
         { 
              UIImagePickerController  *imagePickerController = 
                         [[UIImagePickerController alloc] init];
              imagePickerController.delegate = self;
              imagePickerController.sourceType =
                         UIImagePickerControllerSourceTypePhotoLibrary;
    
              UIPopoverController  *popVC = [[UIPopoverController alloc] 
                                     initWithContentViewController: imagePickerController];
              popVC.delegate = self; 
             [popVC setPopoverContentSize:CGSizeMake(500, 500)];
    
    
             UIView *tempView = gestureRecognizer.view;        
             CGPoint point = CGPointMake(tempView.frame.size.width/2,
                                   tempView.frame.size.height/2);
             CGSize size = CGSizeMake(100, 100);
             [popVC presentPopoverFromRect:
                               CGRectMake(point.x, point.y, size.width, size.height) 
                               inView:self.view 
                               permittedArrowDirections:UIPopoverArrowDirectionAny 
                               animated:YES];
    
           }
         else 
         {
             UIAlertView *alert = [[UIAlertView alloc] 
                                 initWithTitle:@"Error accessing photo library"
                                 message:@"Device does not support a photo library" 
                                 delegate:nil cancelButtonTitle:@"Cancel" 
                                 otherButtonTitles:nil]; 
             [alert show]; 
             [alert release];
          }
    

    }

    愉快的编码。

    【讨论】:

    • 注意:如果你在模拟器上测试这个,模拟器库上应该有图像..
    【解决方案2】:

    当我可怜的客户迁移到 iOS 5 时,他们的 UIPopoverController 被拉离屏幕边缘。这是因为 iOS 5 在对 presentPopoverFromRect 的第一个参数的解释上与 iOS 4 不同。当我确保提供的矩形在矩形和显示器边缘之间为您的 UIImagePickerController 留出足够的空间时,问题就解决了。将整个显示用于 rect 会产生这种不当行为,类似于您所描述的。

    【讨论】:

      猜你喜欢
      • 2013-04-03
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 2012-01-17
      • 2014-11-06
      相关资源
      最近更新 更多