iPad Modal "Log In" View - ios

I've never developed for the iPad before (just iPhone) and there are some views you see on an iPad that you cannot do on an iPhone. Specifically, I'm trying to create a modal 'login/register' type view and I'd like it to mimic the look and feel of the Log In view in the Zillow iPad app.
In Zillow when you press 'Log In' (or Settings for that matter), the background darkens and a window appears in the middle of the screen modally with a flip animation about it's horizontal axis. Here you are given a view containing buttons, text fields, toggle switches, etc.
Is there a cocoa class for this type of view on the iPad? Can you have a regular UIViewController not take up the entire screen and display 'on top' of the root view controller?
EDIT: Just discovered in the View Controller Attributes Inspector, under Simulated Metrics for Size, there is the Form Sheet option which looks similar to what I am going for. These will display on-top of root views?

You present the view modally, or in a storyboard, do a modal segue. In the inspector for the segue, you can change the presentation from default to "form sheet".
If you're doing the modal presentation in code, you can set the modalPresentationStyle property of the controller you're presenting to UIModalPresentationFormSheet.
As you said in your edit, in the storyboard, you can change the size of the view you want to present by setting the size in Simulated Metrics to "form sheet". However, this has no effect on what size the view will appear at run time. It's only used so you can properly layout your view visually. You need to use one of the ways I mentioned above to get the view to appear at the form sheet size.

Related

How to know when a view controller is presented using a 'form sheet' modal presentation style

When presenting a view controller modally, we can set the modalPresentationStyle to .formSheet:
In a horizontally regular environment, the view controller is sized so that its content area is smaller than the screen size and a dimming view is placed underneath the content...
In a horizontally compact environment, this option behaves the same as UIModalPresentationStyle.fullScreen.
I would like my modally presented view controller to update its layout based on whether it is being presented in this reduced-width form style, or as a full screen presentation. But The modal's horizontal size class is always compact, even when full screen on an iPad Pro in landscape.
The horizontal size class of the presenting view controller can tell me what I need to know (as Apple's docs mention above). But that means observing changes in traitCollection in every view controller than can present my modal, just so they pass them on to the modal view controller.
Is there some way for the modal view controller itself to know which style it is using, and be alerted when it changes so it can respond?
One slightly-gross way to at least know the applications size class:
UIApplication.shared.delegate?.window??.rootViewController?.traitCollection

Swift form sheet on iPhone

I am trying to show a simple form sheet on iPhone.
something like this http://static.squarespace.com/static/53449ac2e4b0233041dcf674/t/53937548e4b0c79f2b9b6fb7/1402172750607/TableView.gif?format=500w
I dont wanna use container view though, it shouldn't be that complicated it is just a popover screen that in the middle of the screen with transparent background
However even though I do these steps:
performSegueWithIdentifier("formSheet", sender: self)
form sheet view controller still shown as full screen like a modal view controller.
How to fix this ?
According to the documentation,
The presentation style determines how a modally presented view controller is displayed on the screen. On iPhone and iPod touch devices, modal view controllers are always presented full-screen, but on iPad devices there are several different presentation options. For a list of possible presentation styles, and their compatibility with the available transition styles, see the “UIModalPresentationStyle” constant descriptions.
Thus, you will not be able to show a Form Sheet on an iPhone, unless you use some third-party library to achieve the same effect. Here is one such library: MZFormSheetController.
See the UIViewController Class Reference for more information.

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 :)

Define modal view dimensions ?

I am developping a Master-Detail based iApp and I would like a specific button in the Master pane to trigger the apparition of a "settings" Form Window.
I then set my segue as "modal" and I get a form view covering the whole screen. This form comes from the bottom of the screen.
How do I get my view to appear from a slot at the top of the window and to cover, say, 2-thirds of the screen width and 3-quarters of its height?
Thanks!
You can't readily do it using the modal presentation styles, as they are fixed sizes. It is possible to work around but you need to mess around with resizing private views and it quickly starts to feel a bit fragile and messy.
It's simpler to create your own view controller at whatever size you like, add it as a child view controller and animate it into position yourself. You can even add your own background dimming view.
You lose the convenience of segues and the dismissal code, as you're no longer "presenting" the new VC, but that's not hard to recreate.

Show a translucent/transparent modal view with support for device rotation

I want to show a translucent/transparent modal view that should cover the entire screen except status bar. Also, I shall be having different layouts for portrait and landscape orientation (in that modal view). I have done thorough googling and found some solutions. Below, i am summarizing them as well with their problems:
Add a view directly to the window: This works nice, but the problem
is device rotation. If I go by whatever I have experimented/learnt
so far, the UIWindow bounds do not change on rotating
the device. This poses a problem - I can't have my landscape modal
view unless until I do some sort of transformation on my view -
something which I am reluctant to. I am also not sure, whether it
will work, as I may have a webview of 1/3rd of the screen height and
full device width in portrait (rest area is translucent), and 1/4th of the screen width, full device
height (minus status bar) in landscape. I read that window changes the bounds (size and coordinate space orientation as well) of Root View controller's view bounds - can't I ask it to change the bounds of my modal view as well? After all Root controller view is also added to the window as a subview only.
Adding the modal view to the root controller
view: This is working fine for me so far with my custom root
controller based app. The problem is, I have to write my code as a
generic module, so that it can be used with different types of
applications. So, if the application root controller is one of the
out of the box container root controller ( like
UINavigationController, UITableViewController, etc ), then, is it
allowed to add a subview directly to their view ? i.e. is is not against the
Apple guidelines? While reading documentation, I read somewhere that
we should not play with standard UI controls, like Buttons.
While reading documentation, I also read it somewhere that UIAlertViews are
shown using another Window. How do we do that? is it normal to add
another window to the app? If things are as per the Apple
guidelines, I can try this approach - I shall make my modal view
the root view of another window and display that window.
What I am trying to achieve is very similar to showing UIAlertView, only in my case, I want my view to be fully customizable.
Thanks,

Resources