Got a strange problem. The cancel button that normally is shown at the navigation bar when you add a UIImagePickerController is missing when I add it to my UIPopoverController.
I have tried to subclass the UIImagePickerController and add a navigation button to the navigation bar myself, but it did not show up.
If I select my camera roll the back button gets automatically added, but the cancel button is still missing.
Anyone know what could cause this?
Here is the code i use. Note that _popOver is the instance of my UIPopoverController.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[_popOver setContentViewController:picker animated:YES];
I have tried this code and now I think it's a default behavior. UIImagePickerController usually presented as modal view controller and the aim of Cancel button is to dismiss it. When you put UIImagePickerController into UIPopoverController then Cancel button became meaningless. For dismissing this you can just tap anywhere (except UIPopoverController view). If you want to access UIImagePickerController when UIPopoverController will/did dismissed use UIPopoverControllerDelegate method:
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
UIImagePickerController *imagePicker = (UIImagePickerController*)popoverController.contentViewController;
return YES;
}
Related
I have a UIImagePickerController with a custom cameraOverlayView.
I create the imagePicker like this:
self.overlay = [self.storyboard instantiateViewControllerWithIdentifier:#"OverlayViewController"];
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
// Insert the overlay
self.picker.cameraOverlayView = self.overlay.view;
self.overlay.pickerReference = self.picker;
self.picker.edgesForExtendedLayout = UIRectEdgeAll;
self.picker.extendedLayoutIncludesOpaqueBars = YES;
self.picker.delegate = self.overlay;
[self presentViewController:self.picker animated:NO completion:^{
}];
For some reason, the OverlayViewController's view is misplaced. It seems as if the constraints haven't been calculated. However, if I explicitly call [self.overlay viewWillAppear:NO]; in the completion block, they layout seems to render correctly.
After some investigation it seems as if viewWillAppear and viewDidAppear is not called for the OverlayViewController.
However, these methods are called if I come back to the imagePicker from a modal 'custom gallery viewcontroller'.
I.e:
rootVC-> (No calls) -> imagePicker -> customGalleryVc
customGalleryVc (dismiss modal) -> (Calls to willAppear) -> imagePicker
What is this? Am I missing something with the fundamentals of the view-hierarchy?
Thank you!
View controller lifecycle methods are called only when the view controller is added into the view controller hierarchy.
The first line of the snippet only instantiated the VC. As you access the view property of the VC, its view (you defined in IB) is loaded. That's all, nothing else happened.
So, a suggestion would be that there is no need to use a view controller for your custom overlay. You just need a normal UIView. With IB, you may create the overlay in a xib, or in a storyboard drag a UIView object to the dock (the top bar of a scene where any gesture recogniser appear if you add any) of your current VC, then you can reference them by creating an IBOutlet.
I am seeing a very weird UI bug with the ABPeoplePickerNavigationController on iPad (in landscape) where when a user clicks the search bar in the PeoplePicker then subsequently cancels out, the keyboard is not resigned and the UI of the people picker gets all messed up. Here is a photo of the bug:
The ABPeoplePickerNavigationController is presented in a modal form sheet using the following code:
- (void) openAddressBook
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.delegate = self;
[picker setModalPresentationStyle: UIModalPresentationFormSheet];
[self presentViewController:picker animated:YES completion: nil];
}
The UI is as expected until a user taps on the search field, which brings up the keyboard, then cancels out of the search field, which does not resign the keyboard as it does on iPhone. Also, when the user scrolls the contacts list in this mode, all of the letter headers (i.e. the A header) are pinned where the A header is currently, not at the top of the view directly under the search bar.
Is there a reason that the keybaord is not being resigned here?
I am having difficulty debugging this as the ABPeoplePickerNavigationController is not subclassable, so any help would be greatly appreciated!
That is how UIModalPresentationFormSheet works: by default, it does not dismiss the keyboard when first responder is resigned. Clearly ABPeoplePickerNavigationController is not expecting to be used this way. My suggestion: don't do that. Use a popover or a normal presented view. (My experience is that a popover looks better.)
use [self.view endEditing:YES]; when you are done
I have a storyboard where I created a UINavigationController instance and set its custom class to UIImagePickerController.
If I set imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera in prepareForSegue, everything works fine.
If I set imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary in prepareForSegue, I get a mostly black screen with an empty gray bar on top that I can't dismiss:
[future location of screenshot - I cannot post images]
I can work around this by not using the storyboard. The question I have-- can this be made to work with the storyboard? If not, why not? Why does it only work for presenting the camera?
EDIT: A colleague comments that this may be a new issue for ios7
The code below doesn't work if the segue is triggered by a storyboard
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSAssert([segue.destinationViewController isKindOfClass:[UIImagePickerController class]], #"Destination VC should be UIImagePickerController");
UIImagePickerController *imagePicker = (UIImagePickerController*) segue.destinationViewController;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
}
This question is a duplicate of iOS7 Storyboard image picker not working :(
The answer there:
Initialize the controller UIImagePickerController *controller = [[segue destinationViewController] init];
...appears to work for most people, so I've recommended this be closed as duplicate of that question which has been answered for awhile.
Definitely strange. The only solution I have found so far is here: ios7-storyboard-image-picker-not-working
You have to manually init the UIImagePickerControllerInstance for same reason.
I'm guessing that there is something funky with the 'initWithCodec' method of the UIImagePicker but it is hard to say without access to the source code (gee thanks Apple...).
P.S. Make sure you are also using the right type of segue. UIImagePickerController is picky about how each mode is displayed. 'Camera' can be modal or popover (modal is reccomended). PhotoLibrary MUST be displayed using a popover.
I need to present a viewController as a formSheet when the user taps a 'settings' button in the navigation bar in the iPad side of my universal app. The view is called "SettingsViewController," and it's a View Controller in my iPad Storyboard with an ID of "settings".
I'm not using segues because in my iPad version of the app, I have more than one button in the navigation bar on the left side, so I have to add the buttons progammatically. (can't connect a segue to a nonexistent UIBarButtonItem in the storyboard.)
The functionality I want is there, the presentation is not.
When I present my SettingsViewController, on the iPad, it's presenting as a full screen view.
I need it to be a form sheet.
I'm wrapping it in a NavigationController, which I need and works fine, just need it to present itself in the correct manner.
Here's the code that presents the view:
-(void)showSettings:(id)sender {
SettingsViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:#"settings"];
svc.delegate = self;
svc.modalPresentationStyle = UIModalPresentationFormSheet;
UINavigationController *navcont = [[UINavigationController alloc] initWithRootViewController:svc];
[self presentViewController:navcont animated:YES completion:NULL];
}
I've tried everything I can think of. Any help is deeply appreciated.
Looks like you set the modal presentation style on SettingsViewController but you should have set it on your UINavigationController.
navcont.modalPresentationStyle = UIModalPresentationFormSheet;
I was wondering how I could use 1 button on my ToolBar to open and dismiss my UIPopOver. If I keep tapping the button right now, another PopOver overlaps the previous one. I want ONE button to be able to dismiss and open my PopOver. I tap once, it opens. I tap the button again, it dismisses. Please tell me how. Thanks
In your button tap action event:
if (myPopover.popoverVisible) //self.myPopover if using property
{
[myPopover dismissPopoverAnimated:YES];
return;
}
//continue code here to create/present your MyPopover…
Quick way to do it is to define a UIPopOverController property in your presenting view controller and use this property to instantiate your popover (and accompanying content view controller).
In your presenting view controller you'll need something like:
UIViewController *aViewController = [[UIViewController alloc]init];
self.popOverController = [[UIPopoverController alloc] initWithContentViewController:aViewController];
Then in your button's action to toggle the popOver it should do something like:
if(self.popOverController.popoverVisible) {
[self.popOverController dismissPopoverAnimated:YES];
} else { //Display the popover }
Hope that help