UIActionSheet on iPad comes up from the bottom when the parent view is a UIPopover - ios

On iPad, I have a view that is a popover. There is a button inside the view that shows a UIActionSheet. When I call showFromBarButtonItem:animated, instead of showing up as a popover as I would expect, I instead get an action sheet that comes up from the bottom of the view. Does anyone know a way to force it to be a popover on top of the existing popover? Everything works fine if my view that shows the UIActionSheet is not a popover.

This behavior is probably because you are calling the UIActionSheet object from within your popover controller, which probably has bounds comparable to that of the iPhone screen size. When you call from within this controller the method showFromBarButtonItem:animated: it gets the bounds of this reduced size popover controller and launches the action sheet object just like on an iPhone from the bottom.
What you would probably need to do is nest popover controllers to achieve your desired effect.

Related

Showing a view controller in Modal Dialog programmatically is appearing as full screen

I have 2 swift View controllers and i want the second one to show as a modal dialog ( like bootstrap modal in web) on top of the first view when i click a button. I used the below code to achieve this, but the second view controller is still appearing full screen!
This is the code i execute to show the second view controller
var addCtrl = self.storyboard?.instantiateViewControllerWithIdentifier("mCtrl")
as? ModalContentViewController
addCtrl!.modalPresentationStyle = .Popover
presentViewController(addCtrl!, animated: true, completion: nil)
mCtrl is the storyboard id of the second viewcontroller.
What am i missing here ? My objective is to show the second view controller in a modal dialog.
EDIT : I am trying to make it work on iPhone.
You don't mention whether you're on iPhone or iPad. Assuming you're on iPad, if you want something like a modal dialog, then you'd be better off using UIModalPresentationFormSheet, which in swift I guess would be .FormSheet. If you really want to use a popover, you'll need to tell it where to popover from. You'd do this by setting the sourceView and sourceRect, or the barButtonItem properties of the controller's popoverPresentationController, after the call to presentViewController.
If you're on the iPhone, you'd still get a full screen presentation in both these cases. However, you can get the iPad style presentations if you set the presenting controller to be the presented controller's presentationController's delegate, before the call to presentViewController, and then implement adaptivePresentationStyleForPresentationController:traitCollection to always return UIModalPresentationNone.
Based on Apple's documentation, you try setting preferredContentSize explicitly for the popover view. Something like
addCtrl!.preferredContentSize = CGSizeMake(200, 100)
The value in this property is used primarily when displaying the view controller’s content in a popover but may also be used in other situations. Changing the value of this property while the view controller is being displayed in a popover animates the size change; however, the change is not animated if you specify a width or height of 0.0.

UI for dismissing View Controller presented by UIPopoverPresentationController regardless of Size Class

I have a Universal app, Xcode 7 Beta, targeting iOS 8.
I am presenting a View Controller using UIPopoverPresentationController.
When presented in any Regular Size Class (e.g. Full screen iPad in any orientation), the View Controller appears as a popover, at the size I have set in the preferredContentSize property. A tap outside the bounds of the View Controller will dismiss the popover.
When presented in Compact Width Size Class (e.g. any iPhone in portrait orientation), the "popover" will become a full screen view, sliding in from the bottom to the top.
The Problem
While an iPad popover has built-in dismissal behaviour (i.e. tap outside of the popover), "popovers" presented full-screen do not. And thus need some UI in order to provide the user with a way to dismiss the popover.
Question
What is the best (recommended?) way to present a UI such that it only appears for the Compact Width Size Class, in order to give the user an option to dismiss the (full screen) "popover" View Controller?
Discussion
One approach I have seen is to embed the [View Controller to be presented] in a UINavigationController. A bar button is added to the Navigation Bar, though whose outlet we can tell the presenting View Controller to dismiss the presentation.
However, not only does this require an extra, unwanted hierarchy for the otherwise simple presented View Controller on the iPad, but it requires environment checking (idiom? size class?) in viewDidLoad to programmatically hide the NavigationBar if a Regular Width Size Class (e.g. iPad) is being used. This strikes me as... fragile.
Another option is to do the above, but use Size Classes within Interface Builder to Install/Uninstall the Navigation elements, non-programmatically.
Thoughts?
Related link, discussing the detection of popover mode
Look at Interface Builder, you can make available any view depending on the Size Class currently running on your app :) If i remember well (because I can't check for now as I'm in a bus) you can specify a view to be available in a specific Size Class in the Property Inspector tab of the selected view. That way you just have to add a button or a navigation bar with items in your view and make it available only for Compact widths :) I'll check more specificaly today to take you some screenshots :)

iOS popover with a close button outside

I need to create below thing
Currently i'm using WYPopover , but I can't create the button since it's outside of the popover. Is there any existing solution out there ? Many thanks
Create a bigger popover UIView holding all your child elements (current popover + button) and make its background transparent or however you wish.
Popover-controller's are exclusively used in iPad. If you want to use in iPhone, you should create it in a custom way.
I am not familiar with the XYPopover in Github, but normally the custom created popover should be dismissed whenever the user taps any place in the screen. That is one of the key feature of the popovers.
Normally the custom popovers are build like, adding a hidden parent view and then the visible image of a popover frame on it.
You should to do the following,
Avoid dismissing the parent view on tap of parent-hidden-view.
Add a close button at the area where you want to show the close button, on top of the parent-hidden-view.
Capture the button click and dismiss the view (remove the view from superview)
How to customize your need
Creating custom popover view is not a big task. It will take maxim one day, try it your self.
One Parent view with clear color
One background image of a popover frame.
View-inside popover (this needs to be customized for UIPopover also).
Close button.

Contents of UIPopover change to random orientation when Modal View is visible and iPad rotated

I have a UITableView within a navigation controller shown within a popover. When you press a bar button from within the popover (on a detail view), it shows a modal view. If you rotate the iPad with the popover visible and the modal view on top of that, the popover's content changes to a seemingly random orientation as shown below.
Any idea what's going on here?
UPDATE:
I'm trying to implement a solution, maybe there's a better way. When the modal view is dismissed, I send an NSNotification from - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error to the popover's owner.
When I press cancel, the button is visibly pressed but nothing happens after that and the screen becomes unresponsive. However, rotation still occurs properly.
It would seem that I'm dismissing the popover before the modal view is dismissed. I don't really know any other way of doing this, you're continued help is appreciated.
I had to completely reload the popover and its view controllers. This is the only way I could mask the problem, not solve it, because this seems to be a bug in iOS 3.2.
Have you tried to dismiss the popover and then redisplay it? The UIPopoverController documentation is straightforward in saying that it will often fail to rotate a popover, and suggests redisplaying it as the only solution. I suspect that since your modal view is on top of the view from which the popover was displayed, the popover's controller is not updating its position & orientation.

UIPopover locking background view

I am trying to replicate the iPad passcode view. Which basically is a popover with no arrow direction, that locks the background view kinda like a modal view controller.
My question: Is there a way to lock the underlying background view when presenting a popover.
My idea: The only real solution that i could come up with is placing that popover inside a modal view controller. and presenting it that way.
Thoughts?
Use the modalInPopover property of your view controller: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW72
This question provides some information on making a popover with no arrows, though it's not clear whether it's correct or not: UIPopover without any arrows

Resources