在我的iPad应用程序中,我在弹出控制器中打开照片库。它在iOS 4中运行良好,但现在它还没有在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 :(得分:0)
在我的代码中,我有一个UIImageView,每当我点击它时,带有iPhone库中图像的UIPickerView就会在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];
}
}
快乐的编码。
答案 1 :(得分:0)
当我的可怜客户转移到iOS 5时,他们的UIPopoverController被从屏幕边缘拉出。这是因为iOS 5在解释presentPopoverFromRect的第一个参数时与iOS 4不同。当我确保提供的rect为显示器的rect和边缘之间的UIImagePickerController留出足够的空间时,问题就解决了。使用rect的整个显示将产生这种不正常行为,这类似于你所描述的。