在我的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];
在我的代码,我有一个UIImageView,每当我拍了拍的是,与iPhone图片库的PickerView在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];
}
}
编码愉快。
当我可怜的客户感动到iOS 5,其UIPopoverController正在拟订了屏幕的边缘。 这是因为iOS 5的从iOS 4的在其presentPopoverFromRect的第一个参数的解释不同。 当我确信所提供的矩形留下足够的空间正确,而且显示器的边缘之间你的UIImagePickerController,问题就解决了。 使用整个显示器的矩形会产生这种错误行为,它类似于你所描述的东西。