2011-11-22 4 views
0

을 팝 업 컨트롤러에 열 때입니다. 내 코드에서UIPopOverController의 UIImagePickerController가 iOS 5에서 열리지 않습니다. iPad 응용 프로그램에서

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

, 그것은 아이폰 OS 4에서 잘 작동했지만, 난이 사진 라이브러리를 열기 위해 다음 코드를 사용하고 지금은 아이폰 OS 5에 개방하지, 나는 그것에 탭마다있는 UIImageView를했다 PopOverController에서 iPhone 라이브러리의 이미지가 포함 된 PickerView가 열립니다. 코딩

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와 다르기 때문입니다. 제공된 rect가 사각형과 디스플레이 가장자리 사이에 UIImagePickerController에 충분한 공간을 남겨 두었을 때 문제가 해결되었습니다. rect에 대한 전체 디스플레이를 사용하면 설명 된 것과 같은 오작동이 발생합니다.

관련 문제