UIImagepickerController is not showing camera in full view for iPhone 4.2 - objective-c

When I invoke camera using the UIimagepicker controller it does not show in full screen mode on iPhone with iOS version 4.2, but it does work in iOS 5.
Can anyone tell me the code that needs to be changed and what is the problem with existing code?
I am using the following code:
- (IBAction)takePicture:(id)sender
{
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.allowsEditing = NO;
imagePicker.toolbarHidden = YES;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
imagePicker.wantsFullScreenLayout = YES;
if ([UIImagePickerController respondsToSelector:#selector(isCameraDeviceAvailable:)])
{
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
{
[imagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
}
}
// Show the camera UI and View Finder.
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
Please check the attachment
Image is here

one of the solution is applying scaling trasnformation - here on stack maybe it will help

I don't see why you are doing these 3 things:
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.camPicker.view setUserInteractionEnabled:YES];
Or for that matter why you are caching the instance of UIImagePickerController (this may cause significantly higher idle memory usage for your application compared to discarding the image picker controller between uses).
Does it work better if you don't do these things?

Related

iOS 8 UIActivityViewController and/or UIPopoverController are not dissmissed when clicked outside of them

I have read the UIPopoverController docs and more then 10 stackoverflow solutions which none work in iOS 8.0.2 ipad device.
THE GOAL:
I want to present a sharing view which when clicked outside dissmisses.
THE PROBLEM:
The code works fine below iOS 8.0.
THE CODE (tried many versions...):
NSArray *dataToShare = #[url]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.modalInPopover = YES;
self.act = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.act presentPopoverFromRect:CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2, self.view.bounds.size.width/2, self.view.bounds.size.width/2) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
self.act.delegate = self;
I have added the :
UIPopoverControllerDelegate
WHAT I HAVE TRIED:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
As soon that the
UIPopoverController
is presented the view losses focus and doesn't register touches. Therefore, I can't handle touches outside the self.act rect space in order to force a dissmisal.
also...
NSArray *dataToShare = #[url]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.modalInPopover = YES;
UIPopoverPresentationController *presentationController = [activityViewController popoverPresentationController];
presentationController.sourceView = self.view; // if button or change to self.view.
[self.parentViewController presentViewController:activityViewController animated:YES completion:nil];
and I tried to present the UIActivityViewController and UIPopoverController from the parent which didn't work aswell.
Please help, I lost half day on something this stupid which works on iOS 7.1 and not on iOS 8+ which is ridiculous and I still have no clue why.
I will try to add the cancel button which has also disappeared in iOS8+.
UPDATE 1:
Adding a UIButton inside a UIBarButtonItem didn't help...
UIButton *control = (UIButton *) sender;
[control setFrame:CGRectMake(300, 300, 100, 100)];
[control setBackgroundColor:[UIColor redColor]];
UIBarButtonItem *barButtonItemView = [[UIBarButtonItem alloc] init];
[barButtonItemView setCustomView:control];
[self.popup presentPopoverFromBarButtonItem:barButtonItemView permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
UPDATE 2 - 19.12.2014. (iOS 7.1. - 8.1.2):
The accepted answer works on iOS 8.1. I had some errors with iOS 7.1. so I modified it to work for iOS 7.1. I have stated on which devices the code works in the comments below the answer.
// publish - sharing
NSArray *dataToShare = #[url]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
NSLog(#" SHARING - 1 - ");
[self presentViewController:activityViewController animated:YES completion:^{}];
}
else
{
// Change Rect to position Popover
NSLog(#" SHARING - 2 - ");
self.popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[self.popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width * 3 / 5 ,
self.view.frame.size.width/2,
self.view.frame.size.width/10,
self.view.frame.size.width/10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
How about just add this.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
activityViewController.modalInPopover = YES;
activityViewController.popoverPresentationController.sourceView = self.view;

Statusbar overlapping on UIImagepickercontroller's Camera View in iOS 7 and iOS 8

im using UIImagepickercontroller to take photo and choose existing photos, when the camera view appears, the top portion on camera was covered by the white status bar. How can i remove the status bar or hide the status bar. Many of them saying its a ios 7 bug, it has been fixed in ios 7.1, but still i'm facing this problem.
This is my code to show the imagepickerController
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = (id)self;
imagePicker.sourceType = (buttonIndex == actionSheet.firstOtherButtonIndex ?
UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary);
[self.viewController presentViewController:imagePicker animated:YES completion:nil];
Also i tried by with below codes to hide statusbar
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
This
-(BOOL) prefersStatusBarHidden {
return YES;
}
And This in Delegate
[UIApplication ShareApplication]SetStatusbarHidden:YES];
Right now i'm working with ios8, and this behaviour happening in all ios version.
Please help me out.
Actually the problem is in my rootviewcontroller i'm creating a Statusbar using UIView and setting its constraints for landscape and portrait programmatically
- (void)setTopBar {
if(topBar == nil && [[UIApplication sharedApplication] keyWindow] != nil) {
topBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
topBar.backgroundColor = navController.view.backgroundColor;
topBar.tag = topBarViewTag;
UIView *containerView = [[UIApplication sharedApplication] keyWindow];
[containerView addSubview:topBar];
[containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[view(20)]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:#{#"view" : topBar}]];
[containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"|[view]|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:#{#"view" : topBar}]];
[containerView layoutSubviews];
}
}
so when i commented the above method in ViewwillAppear, status bar where not showing up, so the problem is with my code.
if anyone face the same issue, i suggest you to have a look on your RootViewcontroller, which acts a navigation to all other classes.

iOS 7 - Black preview screen in UIImagePickerController

Using the below code to launch the image picker to capture the image. Can any one help out to close this issue...
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if (self.camera)
{
self.camera = nil;
}
self.camera = [[UIImagePickerController alloc] init];
self.camera.sourceType = UIImagePickerControllerSourceTypeCamera;
self.camera.allowsEditing = NO;
self.camera.delegate = self;
[self presentViewController:self.camera animated:YES completion:NULL];
}
Before launching the UIImagePickerController if you have any GCD in background might be a reason for this issue. In my code have GCD before launching the UIImagePickerController, now removed the GCD it's working fine.

ABPeoplePickerNavigationController auto dismiss without showing addressbook book

I am using ABPeoplePickerNavigationController for selection of address book contact by user. With this code behind action of a button:
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.view.frame=self.view.frame;
[self presentModalViewController:picker animated:YES];
[picker release];
When this code runs it rotates the Landscape UI to Portrait and eventually dismisses the controller that presents this ABPeoplePickerNavigationController.
I am getting this problem only in iOS 5, iPad 2. It's working fine with iOS 6.
I don't believe in 5.x that landscape is supported for this picker. However, try doing it via a different PresentationStyle. I believe it should then work in landscape, i.e:
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:picker animated:YES];

iPad2 Camera code same as iPhone4?

I am making an app for the iPad and want to be able to use the iPad 2 camera if available. Is the code to load the iPad camera the same as for the iPhone 4? I have this same code working on the iPhone version of this app, but do not have an iPad 2 to test with and simulator can't help me with the camera. Below is what I have to determine if camera is available and then to load camera or load library in popup
Basically I just need to know if the line below is supported by the iPad 2 camera or do I need to use something else?
[self presentModalViewController:imagePickerController animated:YES];
I want camera to be full screen and not in a popup.
- (IBAction) takePhoto:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self presentModalViewController:imagePickerController animated:YES];
} else {
imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
imageView.contentMode = UIViewContentModeScaleAspectFit;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popover setDelegate:self];
[popover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
Yes this works, for sure if self is a UINavigationController. I know this because I do the same in my app. I'm not sure for other UIViewControllers, but it stands to reason that it will also work.