如何在ipad中添加UIImagePickerViewController作为子视图?

时间:2012-09-18 09:22:35

标签: ipad ios4 uiimagepickercontroller

如何在ipad中添加UIImagePickerViewController作为子视图。

在iphone中我用这样的工作正常

self.pick = [[UIImagePickerController alloc]init];
pick.delegate = self;
pick.sourceType = UIImagePickerControllerSourceTypeCamera;
pick.sourceType = UIImagePickerControllerCameraDeviceFront;
pick.showsCameraControls = NO;
CGRect rect = CGRectMake(0, 0, 200, 250);
pick.view.frame = rect;
UIView *cameraView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];   
[cameraView setBackgroundColor:[UIColor greenColor]];
[cameraView addSubview:pick.view];
[self.view addSubview:cameraView];
[pick viewWillAppear:YES];
[pick viewDidAppear:YES];
[pick release];

但同样的方法我垫不工作。当相机打开时,ipad正在全视图。 我不想使用popoverview控制器。 请帮助我?

1 个答案:

答案 0 :(得分:3)

在iPad上

UIImagePickerController 必须出现UIPopoverController

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
    [popover presentPopoverFromRect:self.selectedImageView.bounds inView:self.selectedImageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    self.popOver = popover;
} else {
    [self presentModalViewController:picker animated:YES];
}