UIImagePickerController in UINavigationController - ios

Guyz, I am displaying UIImagePickerController in UINavigationController but some frame of image picker controller hides under nav bar .Do any Body has the solution and code is
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
//[picker.view setFrame:CGRectMake(0,50, 800, 600)];
self.nv=[[UINavigationController alloc]init];
[self.nv.view setFrame:(CGRectMake(0, 50, 320.0, 400.0))];
// 4. add the nav bar to the main view
[self.nv addChildViewController:picker];
[picker didMoveToParentViewController:self.nv];
picker.view.frame = CGRectMake(15, 50, 290, 400);
popoverController = [[UIPopoverController alloc] initWithContentViewController:self.nv];
[popoverController presentPopoverFromRect:[(UIButton *)sender frame]
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];

Try this alternate. :)
#define ISIPHONE [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
UIPopoverController *popover;
- (IBAction)openImagePicker:(UIButton *)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //UIImagePickerControllerSourceTypeCamera
if (ISIPHONE)
{
[self presentViewController:picker animated:YES completion:NULL];
}
else
{
if (!popover)
{
popover = [[UIPopoverController alloc] initWithContentViewController:picker];
}
[popover presentPopoverFromRect:sender.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

Related

How to set popover to fullscreen in ios

I want to make a popover to fullscreen
popover = [[UIPopoverController alloc] initWithContentViewController:cameraUI];
[_popover presentPopoverFromRect:CGRectMake(0, 0, 0, 0) inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUnknown animated:YES];
who know how to do it in ios7/ios8
well anyway if your problem is it's not working on a phone then add a category like this
#interface UIPopoverController (phone)
+ (BOOL)_popoversDisabled;
#end
#implementation UIPopoverController (phone)
+ (BOOL)_popoversDisabled {
return NO;
}
#end
then doing a popover like this seems just fine. so again, not sure what your actual problem is (if any)
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
UIPopoverController * popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:CGRectMake(0, 0, 0, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUnknown animated:YES];

Can't present imagepicker immediately

I have a Tab bar controller, when I tap the third tab bar button I present a UIViewcontroller. In the viewWillAppear of this vc I'm presenting a UIImagepickerController that works fine. The problem is I can't display it on the screen immediately when I open the view. First the vc shows up and after 0.4-0.5 sec the image picker. So I would like to present the image picker first and present the vc after the user took an image. I tried to call the picker from viewDidLoad and viewWillAppear too, but nothing changed.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (imagePickerWasPresented == NO)
{
imagePickerWasPresented = YES;
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = YES;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
}
Am I calling it in a wrong place?
I had the same problem - instead of calling the VC and then the UIImagePicker, call the UIImagePicker directly.
When you are done taking a picture/video:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {}
you will go to this standard delegate method, call the VC from here. This way you will immediately go to the ImagePicker and only have a transition would you choose to do something with the taken content afterwards which is less frustrating/ugly.
No, your calling it in an okay place, that's just how iOS does it; if you present multiple modals on top of each other, one gets presented after the other, including the animation. A solution that would work for your problem is to present a UINavigationController instead of your UIViewController. Set the navigation controller up to have ViewController as the root viewcontroller, but also push your imagepickercontroller onto the stack. Present this navigationcontroller and it should go right to your imagepickercontroller. Otherwise, try presenting both uiviewcontroller and imagepickercontroller with animation set to NO and see if that works.
try this to see how close that gets you then adapt to your needs. when i gave it a quick test it seemed to do what you were asking.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
UIViewController * vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
UINavigationController * navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:vc animated:NO];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:navigationController, nil];
tabBarController.viewControllers = controllers;
tabBarController.delegate = self;
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
[vc presentViewController:imagePicker animated:NO completion:nil];
return YES;
}
UIImage as a PopOver
Gallery mode:
BOOL hasGallery = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = hasGalleryt ? UIImagePickerControllerSourceTypePhotoLibrary : UIImagePickerControllerSourceTypePhotoLibrary;
if (self.popoverController != nil)
{
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController=nil;
}
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
CGRect popoverRect = [self.view convertRect:[self.imageView frame]
fromView:[self.imageView superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 300) ;
popoverRect.origin.x = popoverRect.origin.x;
[self.popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Camera mode:
BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = hasCamera ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary;
if (self.popoverController != nil)
{
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
CGRect popoverRect = [self.view convertRect:[self.imageView frame]
fromView:[self.imageView superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 300) ;
popoverRect.origin.x = popoverRect.origin.x;
[self.popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Remember to give to the .h File #interface the delegates, like this:
#interface the UIViewController: UIViewController <UIPopoverControllerDelegate, UIImagePickerControllerDelegate>

Create UISegementControl and UIImagePicker in same UIPopoverController

I am creating a UISegementControl in UIPopoverController. How can i add UIImagePicker in that same UIPopoverController.
segmentController *segmentCtrl = [[segmentController alloc] init];
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:segmentCtrl];
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
[imgPicker setDelegate:self];
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:navCtrl];
[popOver setPopoverContentSize:CGSizeMake(300, 500) animated:YES];
popOver.delegate = self;
self.popoverImageViewController = popOver;
[self.popoverImageViewController presentPopoverFromBarButtonItem:button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
In the above code It's create a UISegementControl in UIPopoverController. But i need to add also UIImagePicker in that UIPopover...
If i made any mistake. Please correct me.
Try doing something like this.
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(768, 1000);
NSArray *itemArray = [NSArray arrayWithObjects: #"One", #"Two", #"Three", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
[containerController.view addSubview:imagePickerController.view];
[containerController.view addSubview:segmentedControl];
popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
//add ur segment control on top it would take 44 px then adjust the imagePicker frame accordingly.
CGRect tFrame = containerController.view.frame;
tFrame.origin.x -= 44;
tFrame.size.height -=44;
[imagePickerController.view setFrame:containerController.view.frame];

UIImagePickerController with PopOver not working on iPad Device

I am using the UIImagePickerController for picking the image and use the image in ipad application it works fine on simulator but it does not open imagepickerController in device here is my code
else if([labelType.text isEqualToString:#"Select Image"]){
selectedType=#"Select Image";
BOOL isiPhone;
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if (isiPhone) {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
{
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pckrImage animated:YES];
}
else {
}
}
else
{
popOver = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
[popOver presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
Please make change as
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if (isiPhone) {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
{
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pckrImage animated:YES];
}
else {
}
}
else
{
UIPopoverController *popOver = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
self.popoverImageViewController = popOver;
[self.popoverImageViewController presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
Initialize the object
#property (strong,nonatomic) UIPopoverController *popoverImageViewController;
Try this:
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (isiPhone) {
[self presentModalViewController:pckrImage animated:YES];
}
else
{
popOver = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
[popOver presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
Hope this helps.
Try to present the popover with UIPopoverArrowDirectionAny.
[self.popoverController presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];

how to display cameracview in popOvewView in ipad

Hi for all i am using popoverController displaying for camera view but i am not getting camera view anybody please help me here s my code.
picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=NO;
picker.delegate = nil;
picker.allowsEditing = NO;
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(768, 750);
[containerController.view addSubview:picker.view];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:containerController];
self.popoverController = popover;
popoverController.delegate = self;
[popover release];
CGPoint point = {760,750};
CGSize size = {760,750};
[popoverController presentPopoverFromRect:CGRectMake(point.x, point.y, size.width, size.height)
inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
here i am getting empty popoverView? video is not displayed.
I couldn't find the issue. Please check with this code:
picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls=NO;
picker.delegate = nil;
picker.allowsEditing = NO;
picker.contentSizeForViewInPopover = CGSizeMake(768, 750);
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.popoverController = popover;
popoverController.delegate = self;
[popover release];
CGPoint point = {760,750};
CGSize size = {760,750};
[self.popoverController presentPopoverFromRect:CGRectMake(point.x, point.y, size.width, size.height) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

Resources