2011-11-22 30 views
0

在我的iPad應用程序中,我正在打開Popover控制器中的Photo Library。這是工作的罰款中的iOS 4,但 我用下面的代碼打開圖片庫,現在它不是在IOS 5對外開放,UIPopOverController中的UIImagePickerController未在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]; 

回答

0

在我的代碼,我有一個UIImageView,每當我對竊聽,在PopOverController中打開PickerView與iPhone庫中的圖像。

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

}

編碼愉快。

+0

注意:如果你正在模擬器上測試,模擬器庫上應該有圖像。 –

0

當我的窮人客戶轉移到iOS 5時,他們的UIPopoverController被拖出屏幕邊緣。這是因爲iOS 5在解釋presentPopoverFromRect的第一個參數方面與iOS 4不同。當我確定提供的矩形在顯示器的矩形和邊緣之間爲UIImagePickerController留下了足夠的空間時,問題就解決了。使用rect的整個顯示會產生這種不良行爲,這與您所描述的相似。

相關問題