Hello There!
I am trying to present a UIPopoverController using presentPopoverFromRect: but when i present the popover using the button's coordinates the popover appears somewhere obscure like the top left or bottom right corner of the screen. Any Ideas?
Here is my code:
Code:
- (IBAction)getPhoto:(id)sender {
if ([imagePickerPopover isPopoverVisible]) {
[imagePickerPopover dismissPopoverAnimated:YES];
//[imagePickerPopover release];
} else {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
if((UIButton *) sender == choosePhoto) {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
CGRect choosePhotoRect;
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
choosePhotoRect.origin = [sender frame].origin;
choosePhotoRect.size.width = 1;
choosePhotoRect.size.height = 1;
[imagePickerPopover presentPopoverFromRect:choosePhotoRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
} else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
choosePhotoRect.origin = [sender frame].origin;
choosePhotoRect.size.width = 1;
choosePhotoRect.size.height = 1;
[imagePickerPopover presentPopoverFromRect:choosePhotoRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
} else {
CGRect takePhotoRect;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
takePhotoRect.origin = [sender frame].origin;
takePhotoRect.size.width = 1;
takePhotoRect.size.height = 1;
[imagePickerPopover presentPopoverFromRect:takePhotoRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
} else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
takePhotoRect.origin = [sender frame].origin;
takePhotoRect.size.width = 1;
takePhotoRect.size.height = 1;
[imagePickerPopover presentPopoverFromRect:takePhotoRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
}
}
Regards
Toby...