UIImagePickerController in UIPopOverController is not opening up in iOS 5

假如想象 提交于 2019-12-12 02:18:34

问题


in my iPad app i am opening Photo Library in a popover controller. It was working fine in iOS 4 but now its not opening up in iOS 5. i am using the following code for opening Photo Library,

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

回答1:


In my code, I had a UIImageView, whenever I tapped on that, the PickerView with Images from iPhone Library gets opened in 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];
      }

}

Happy coding.




回答2:


When my poor customers moved to iOS 5, their UIPopoverController was being drawn off the edge of the screen. This is because iOS 5 differs from iOS 4 in its interpretation of presentPopoverFromRect's first parameter. When I made sure the supplied rect leaves enough room for your UIImagePickerController between the rect and the edge of the display, the problem was resolved. Using the entire display for the rect will produce this misbehavior, which resembles what you've described.



来源:https://stackoverflow.com/questions/8222288/uiimagepickercontroller-in-uipopovercontroller-is-not-opening-up-in-ios-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!