image picker appears momentarily on IPad - objective-c

I have the following code:
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
popover = [[UIPopoverController alloc] initWithContentViewController:picker];
popover.delegate = self;
[popover presentPopoverFromRect:self.view.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[picker release];
It should place an image picker dialog on screen in IPad. It works OK on simulator, but on device the picker appears momentarily and disappears.
Any ideas how to fix?

UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.popoverController = popover;
popoverController.delegate = self;
[self.popoverController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[picker release];

Related

Shift to UIPopoverPresentationController

I want to create the same popover for my iPhone app with size GGrect of (320 100.0).
Here is my old code:
View * pk1 = [[View alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:pk1];
pop = [[UIPopoverController alloc] initWithContentViewController:nav];
[pop setDelegate:self];
[pop presentPopoverFromRect:[self btnsavepart].frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[nav release];
I using this codes but its doesn't change
nav.preferredContentSize = CGSizeMake(320, 100);
I can not change UIpopovercontriller with UIPopoverPresentationController.
How do I specify GGrect of (320 100.0)?
i thinks i can change only on horizontally but how can i do.
View *viewController = [[[View alloc] init] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
navController.modalPresentationStyle = UIModalPresentationPopover;
navController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
navController.popoverPresentationController.sourceRect = btnsavepart.bounds;
navController.popoverPresentationController.sourceView = btnsavepart;
navController.popoverPresentationController.delegate = self;
[self presentViewController:navController animated:YES completion:nil];
i want the UIPopoverPresentationController not FullScreen form in iPhone
i adding this codes but i give the FullScreen view
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return NO;
}
I work with Xamarin but its same thing , to specify size of the popover in which you want to display your UIViewController, in the properties of your UIVIewController you have the PreferredContentSize property. There you specify the size.
I saw it somewhere here but forgot where.

How to change the size width of UIImagePickerController on iPad?

How to change the size width of UIImagePickerController on iPad? I can change the height so it is 700 but can't change width and it still 320.
My code.
UIImagePickerController* imagePicker=[[UIImagePickerController alloc]init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate=self;
CGRect myRect = CGRectMake(imagePicker.view.frame.origin.x, imagePicker.view.frame.origin.y, 720, 700);
imagePicker.view.frame = myRect;
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
myRect = CGRectMake(100, 880, 900, 900);
CGRect re2 = CGRectMake(0,0,800,800);
[self.popover setPopoverContentSize:re2.size];
[self.popover presentPopoverFromRect:[self.view bounds] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popover setPopoverContentSize:re2.size];
I had your same problem and I solved with the UINavigationControllerDelegate, since the UIImagePickerView content for the PhotoLibrary is a navigatorController. When you select a row it changes ViewController and the size of the popover changes as well.
So, in your willShowViewController delegate just put:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
viewController.contentSizeForViewInPopover = CGSizeMake(800, 800);
}
This will prevent the resizing of the popover.
This simplified code worked fine for me:
UIImagePickerController* imagePicker=[[UIImagePickerController alloc]init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[self.popover presentPopoverFromRect:CGRectMake(100, 880, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popover setPopoverContentSize:CGSizeMake(700, 700)];
iOS 9 and above.
Another way is it to use ContainerViewController and add UImagePickerViewController to ContainerViewController. overriding size in UINavigationControllerDelegate methods has its limits. (not possible to go down on height below 600pt)
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.preferredContentSize = CGSizeMake(320, 480);
UIViewController *containerViewController = [[UIViewController alloc] init];
containerViewController.preferredContentSize = _imagePicker.preferredContentSize;
[containerViewController addChildViewController:_imagePicker];
[containerViewController.view addSubview:_imagePicker.view];
[_imagePicker didMoveToParentViewController:containerViewController];
if (!_imagePickerPopover) {
//customize PopoverController, use your own
_imagePickerPopover = [[PopoverController alloc] init:cnt];
}

Display full camera in iPad

I am try to display full camera in iPad. but it displays very small camera. I am using below this code.
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate=self;
imagePicker.cameraOverlayView.frame = CGRectMake(0, 0, 1000, 700);
[imagePicker.cameraOverlayView sizeToFit];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
imagePicker.wantsFullScreenLayout = YES;
[imagePicker release];
[popover presentPopoverFromRect:CGRectMake(0,0,400,800)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
UIImagePickerController is a UINavigationController. Just show it as a full screen modal view controller instead of in a popover.
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:ipc animated:YES completion:nil];
You only need to use a popover on the iPad for selecting images from the photo library. But the camera is allowed to be shown full screen without a popover.

hidden navigation bar causing trouble with action sheet

The navigation bar in my uinavigationbarcontroller is hidden, but my actionsheet thinks its still there, hence giving me a the highlights at the top of the action page (seen above). How can I erase this/ trick my actionsheet into thinking its a normal uiimageview?
Navigation bar hidden like so in didLoad:
[self.navigationController setNavigationBarHidden:YES animated:NO];
and:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (![self.navigationController isNavigationBarHidden])
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
}
actionsheet looks like this in didLoad:
actionSheet = [[UIActionSheet alloc] initWithTitle:#"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 200,320,16)];
[pickerToolbar sizeToFit];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonSystemItemCancel target:self action:#selector(cancel_clicked:)];
[barItems addObject:cancelBtn];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:self action:#selector(done_clicked:)];
[barItems addObject:doneBtn];
[pickerToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerToolbar];
UIPickerView *locationPicker = [[UIPickerView alloc] init];
locationPicker.frame = CGRectMake(0, 244, 320, 216);
locationPicker.delegate = self;
locationPicker.dataSource = self;
locationPicker.showsSelectionIndicator = YES;
locationPicker.tag = 1;
[actionSheet addSubview:locationPicker];
Then its animated in on textfield touch.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField == locationTextField.self)
{
[actionSheet showInView:self.view];
[actionSheet setFrame:CGRectMake(0, 0, 320, 480)];
[nameField resignFirstResponder];
}
}
I believe the problem is with the view you chose to show the action sheet. try to show it in your app's main window.

How can I create unique PopoverView

How can I create special popOver?
I have manually created a new class, with needed design.
Then I want to load it like a PopOver
-(void) buttonAction {
UIViewController* popoverContent = [[UIViewController alloc] init];
myThirdPop * showHere;//Created class which I load as Popover
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
showHere = [nib objectAtIndex:0];
popoverContent.view = showHere.myView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(300, 350);
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:myButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
But when I trying to tap the button, my app crashes with exc_bad_access
What`s wrong?
Use this code to create the popover
-(IBAction)Click_event
{ UIPopoverController *popoverview;
if(![popoverview isPopoverVisible])
{
Popview *pop = [[Popview alloc] initWithNibName:#"Popview" bundle:nil];
popoverview = [[UIPopoverController alloc] initWithContentViewController:pop];
[popoverview setPopoverContentSize:CGSizeMake(600.0f, 500.0f)];
[popoverview presentPopoverFromRect:CGRectMake(400, 400, 0, 0) inView:self.Click_but permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else
{
[popoverview dismissPopoverAnimated:YES];
}
}
Lets try this. It may be helpful for you
Try this way u may fix the issue....
PopimagepickerViewController.h
UIPopoverController *popoverController;
UIPopoverController *popoverimagview; // imagepicker popoverview
PopimagepickerViewController.m
-(IBAction)popbtn_Click:(id)sender
{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,230,180)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view=popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(230, 180); // Set the popoverview Width and height
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
CGRect popoverRect = [self.view convertRect:[popbtn frame]
fromView:[popbtn superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100) ;
popoverRect.origin.x = popoverRect.origin.x;
[popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp +
UIPopoverArrowDirectionLeft //pooverview down direction
animated:YES];
[popoverView release];
[popoverContent release];
}
Your code seems overly complex, and non standard. I use this code to create a popover.
(I've edited this to match your case, but it's not tested)
-(void) buttonAction:(id) sender
{
UIViewController *myThirdPop = [[NSBundle mainBundle] loadNibNamed:#"myThirdPop" owner:self options:nil];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:myThirdPop];
[popoverController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[myThirdPop release];
}