1

このコードを iPad で動作させるには助けが必要です。iPhone では正常に動作しますが、なんらかの理由で iPad では動作しません。この画像ピッカーを iPad で動作させるにはどうすればよいかわかりません。どんな助けでも大歓迎です。

  -(IBAction)getCameraPicture:(id)sender
    {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = (sender == takePictureButton) ?    UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController: picker animated:YES];
[picker release];
     }

   -(IBAction)selectExitingPicture
{
if([UIImagePickerController isSourceTypeAvailable:
   UIImagePickerControllerSourceTypePhotoLibrary])
{
    UIImagePickerController *picker= [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}


  }

 -(void)imagePickerController:(UIImagePickerController *)picker
 didFinishPickingImage : (UIImage *)image
 editingInfo:(NSDictionary *)editingInfo
   {
imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
   }


   -(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
 {
[picker dismissModalViewControllerAnimated:YES];
  }
4

3 に答える 3

2

iPhoneでUIImagePickerそのまま表示できます。modalViewただし、iPad では、imagePicker を表示するためのコンテナーとして UIPopover を使用する必要があります。

次のようにコードを書き直します。

-(IBAction)selectExitingPicture
{
  if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
  {
    UIImagePickerController *picker= [[UIImagePickerController alloc]init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
      self.popover = [[UIPopoverController alloc]
            initWithContentViewController:picker];
        popover.delegate = self;
        [self.popover presentPopoverFromRect:CGRectMake(0,0,170,250)
            permittedArrowDirections:UIPopoverArrowDirectionAny
            animated:YES];
    }
    else
    {
       [self presentModalViewController:picker animated:YES];
    }
   [picker release];
}

@interface必要なプロトコルと必要なインスタンスを追加します

@interface yourController: UIViewController
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate, UIPopoverControllerDelegate>
{
    UIPopoverController *popover;
}
@property (nonatomic, strong) UIPopoverController *popover;
@end

iPad と iPhone の両方で動作します。

于 2012-11-23T17:35:52.970 に答える
2

iPad では、モーダルで表示するのではなく、UIPopoverController 内で表示する必要があります。

于 2012-11-23T17:04:55.720 に答える
0

これを試すことができます:

カスタム ポップオーバーの CGRectMake とコンテンツ サイズの CGSizeMake を変更します。

    - (IBAction)imageFromAlbum:(id)sender
{
    imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    // es iPad
    if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

        //Averiguar si está en portrait o landscape
        UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

        //PORTRAIT
        if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
        {

            [self cerrarTeclado];

            self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
            self.popover.delegate = self;

            [self.popover presentPopoverFromRect:CGRectMake(600, 400, 311, 350) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
            [self.popover setPopoverContentSize:CGSizeMake(330, 515)];

        }
        //LANDSCAPE
        if (orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft)
        {

            self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
            self.popover.delegate = self;

            [self.popover presentPopoverFromRect:CGRectMake(850, 400, 311, 350) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
            [self.popover setPopoverContentSize:CGSizeMake(330, 515)];

        }

    } else {
       // no es iPad 
       [self presentViewController:imagePicker animated:YES completion:nil]; 
    }


}
于 2013-08-17T21:54:54.597 に答える