TabBar does not work after hidden = NO - ios

I am faced a problem: after command self.tabBarController.tabBar.hidden = YES, I do something and then call: self.tabBarController.tabBar.hidden = NO, tabs do not work at all. It looks like frozen
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
self.tabBarController.tabBar.hidden = TRUE;
imagePickerController.showsCameraControls = YES;
}
self.imagePickerController = imagePickerController;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:NULL];
self.tabBarController.tabBar.hidden = FALSE;
}
after pressing Cancel tab bar is appearing but tabs do not work at all

Related

Display photos taken in different image views

I have two image views. When I click a button (e.g. takePhoto) underneath of the 1st image view, the photo taken appears in the first image view. However, when I tap the second "takephotoTwo" button, I want the second photo taken to appear in the second image view (imageTwo). Right now, if I take a photo using the second "takephotoTwo" button, the final (same) image appears in both image views. See code below - does anyone know how I can fix this? I hope I explained this well enough.
E.g.
The photo taken with takePhoto (button) should appear in imageView, and the photo taken with takephotoTwo (button) should appear in imageTwo.
ViewController.m
- (IBAction)selectPhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *secondImage = info[UIImagePickerControllerEditedImage];
self.imageTwo.image = secondImage;
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
This is easily achieved by keeping track of which button was tapped or storing a reference to the proper image view based on which button was tapped. Then in the image picker delegate method you set the appropriate image view.
Add an instance variable of type UIImageView * named selectedImageView.
Then update the rest of your code as follows:
- (IBAction)selectPhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
selectedImageView = self.imageView; // Add this
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
selectedImageView = self.imageView; // Add this
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
selectedImageView = self.imageTwo; // Add this
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
selectedImageView = self.imageTwo; // Add this
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerEditedImage];
selectedImageView.image = image;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
The problem is that no matter which button is tapped, you are giving your UIImagePickerController the same delegate. Therefore the same imagePickerController:didFinishPickingMediaWithInfo: is called. But at that point you have no way of knowing which button was tapped, so you have no way of knowing what image view to put the picture into.
Either give the UIImagePickerController a different delegate for each different button, or store in an instance variable somewhere some information about which button was tapped, so that imagePickerController:didFinishPickingMediaWithInfo: can decide correctly what to do.

iOS App - Trying to Get iOS photo from gallery but getting an error

I'm new to iOS coding, so my apologies in advance. I know this topic has been covered many times (I searched) however I can't seem to resolve my problem, which is why I am posting.
I am trying to access the iOS photo gallery but I keep getting two errors:
One is
'Application tried to present a nil modal view controller on target .'
Edit: The above error was fixed by initing the _picker in ChooseExsisting, as was suggested in the comments.
The other
[CameraController ChooseExsiting:]: unrecognized selector sent to instance 0x157e11330'
My code is as follows:
- (IBAction)ChooseExsiting {
UIImagePickerController *pickerController = [[UIImagePickerController alloc]
init];
pickerController.delegate = self;
[self.picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:_picker animated:YES completion:NULL]; }
I imagine my ChooseExsisting code is incorrect. Would anyone have any suggestions? I would greatly appreciate it.
In your ChooseExisting method, you instantiate a controller into a local variable, but then call present with _picker property variable which is probably nil. Either present the controller from the local variable or init the property like in TakePhoto method.
EDIT: As for the second part, both your IBActions have a wrong method signature if you are connecting them to Tap handlers in the Storyboard for example. They should look like this:
- (IBAction) TakePhoto:(id)sender
- (IBAction) ChooseExsiting:(id)sender
Change your ChooseExisitng method to below one:
- (IBAction)ChooseExsiting:(id) sender {
UIImagePickerController *pickerController = [[UIImagePickerController alloc]
init];
pickerController.delegate = self;
[pickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:pickerController animated:YES completion:NULL]; }
or
- (IBAction)ChooseExsiting:(id) sender {
self.picker = [[UIImagePickerController alloc]
init];
self.picker.delegate = self;
[self.picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:self.picker animated:YES completion:NULL]; }
You can try this . It work for me
Follow below three steps1.First of all you need to add below delegate in .h file (UIImagePickerControllerDelegate,UIPickerViewDelegate)
2.Add below three methods in your controller
3. On button click call below methods
here choose photo for open gallary. so on button click call choose photo method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
CGSize newSize=CGSizeMake(150, 150);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[[info objectForKey:UIImagePickerControllerEditedImage] drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
img_profile_pic.image = newImage;
[self dismissViewControllerAnimated:YES completion:nil];
isProfilePic=TRUE;
}
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.allowsEditing = YES;
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
imagePickerController = imagePickerController;
[self presentViewController:imagePickerController animated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void) takePhoto{
[self showImagePickerForSourceType:UIImagePickerControllerSourceTypeCamera];
}
-(void) choosePhoto{
[self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
Instead of doing
if ([UIImagePickerController isSourceTypeAvailable:!UIImagePickerControllerSourceTypeCamera]) {
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
[self.picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:_picker animated:YES completion:NULL];
} }
You should do this
if ([UIImagePickerController isSourceTypeAvailable:!UIImagePickerControllerSourceTypeCamera]) {
if(!_picker){
_picker = [[UIImagePickerController alloc] init];
_picker.delegate = self;
[_picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:_picker animated:YES completion:NULL];
}else{
[self presentViewController:_picker animated:YES completion:NULL];
}}}
You should initialize _picker property before presenting it, right now you're trying to initialize local property of VC or you can also present self.picker instead of _picker in your code.

MPMediaPickerController very slow on iPad ios7

I am trying to display a MPMediaPickerController in a popover on iOS7+ and it is VERY slow. It takes about 4 seconds from the first NSLog to the second NSLog. I have tried retaining the picker but this makes no difference. Any ideas would be greatly appreciated.
- (void) showMediaPickerControllerWithArrowDirection:(UIPopoverArrowDirection)arrow_direction
{
MPMediaPickerController *self.picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
self.picker.modalPresentationStyle = UIModalPresentationPopover;
self.picker.delegate = self;
self.picker.allowsPickingMultipleItems = YES;
UIPopoverPresentationController *popPresenter = self.picker.popoverPresentationController;
popPresenter.sourceView = self.view;
popPresenter.sourceRect = self.view.bounds;
popPresenter.permittedArrowDirections = arrow_direction;
NSLog(#"____________________________ about to launch picker ");
[self.viewController presentViewController:self.picker animated:YES completion:^{
NSLog(#"____________________________ picker launched ");
}];
}

Using .xib file as the custom camera overlayview

I created a CameraOverlayViewController with .xib file to implement a customized camera overlayView with. The overlayView is just a transparent background with a button to select photo from the photoLibrary and it loads successfully in the mainViewController with the following code:
CameraOverlayViewController* overlay = [[CameraOverlayViewController alloc] initWithNibName:#"CameraOverlayViewController" bundle:nil];
cameraPicker.cameraOverlayView = overlay.view;
However, nothing happens when I pressed the button on the cameraOverlayView. No error messages, nothing. Does anyone know what's going on here? Below is my code in the CameraOverlayViewController file:
- (IBAction)select:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:picker
animated:YES completion:nil];
}];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
NSLog(#"Just work alrdy!!!");
}
Thanks in advance!
Try This..
-(IBAction)select:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:picker
animated:YES completion:nil]; ////////check this is called??????
}];
}

Dismiss a imagepickercontroller

I'm trying to dismiss a imagepickercontroller (album or camera) which is presented as below
[self.view.window.rootViewController presentViewController:imagePicker animated:YES completion:nil];
By calling :
[self dismissViewControllerAnimated:YES completion:NULL];
I can't dismiss the imagepickercontroller.
Any body can help me on this?
I use this:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
[self dismissViewControllerAnimated:YES completion:nil];
else
[popover dismissPopoverAnimated:YES];
Don't know whether the NULL rather than nil would matter, but it should be nil.
The picker is presented with the following code:
- (void)getVideoFromDevice
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // for ipad only
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = NO;
imagePicker.videoQuality = UIImagePickerControllerQualityTypeLow;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromBarButtonItem:[self.navigationItem.rightBarButtonItems objectAtIndex:0] permittedArrowDirections: UIPopoverArrowDirectionAny animated:YES];
}
else // for iphone only - NOT TESTED
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
I haven't tested the code for iPhone yet but the iPad portion is working correctly.
You need to dismiss the UIImagePickerViewController in the delegate methods: imagePickerController: didFinishPickingMediaWithInfo: and imagePickerControllerDidCancel:. Just be sure to assign the UIImagePickerViewController delegate to the UIViewController that presents the UIImagePickerViewController.
Example:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{
[picker dismissViewControllerAnimated:YES completion:nil];
}

Resources