Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.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
Ipad UIPopOverController中的UIImagePickerController在iOS 5中未打开_Ipad_Ios5_Uiimagepickercontroller_Uipopovercontroller - Fatal编程技术网

Ipad UIPopOverController中的UIImagePickerController在iOS 5中未打开

Ipad UIPopOverController中的UIImagePickerController在iOS 5中未打开,ipad,ios5,uiimagepickercontroller,uipopovercontroller,Ipad,Ios5,Uiimagepickercontroller,Uipopovercontroller,在我的iPad应用程序中,我正在popover控制器中打开照片库。它在iOS 4中运行良好,但现在在iOS 5中无法打开。 我使用以下代码打开照片库 UIImagePickerController* picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self;

在我的iPad应用程序中,我正在popover控制器中打开照片库。它在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];

在我的代码中,我有一个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];
      }
}


快乐编码

当我可怜的客户转向iOS 5时,他们的UIPopoverController被从屏幕边缘拉了出来。这是因为iOS 5与iOS 4在解释PresentPooverFromRect的第一个参数时有所不同。当我确保提供的rect在rect和显示器边缘之间为UIImagePickerController留出足够的空间时,问题得到了解决。将整个显示器用于rect将产生这种错误行为,这与您所描述的类似。

注意:如果您在模拟器上进行测试,模拟器库中应该有图像。。