What is the general pattern for supporting a different display on a VC rotation?
Would I create a new VC in interface builder, design it, etc.. Then on willRotate, segue to it? Or what is the proper way to handle this?
Example, tableview in portrait.
Rotate left, and now show a graph
I eneded up adding a different view controller designed sideways. Then I used the rotation delegate methods to figure out when something rotates to make the move.
Related
For those that use the iOS Calendar a lot, you know that when you change the orientation of the phone, another view is presented. I am not sure oof this is changing to a subview, a new UIViewController, size classes or some programatic voodoo that Apple has spun.
I can do some of the features with a subview that changes constrains on orientation change, but that is about it. It looks crude and I thought there might be a better way to imitate the Calendar App.
It most likely uses UISplitViewController to achieve this effect. This lets you display two child view controllers side by side.
You can change its preferredDisplayMode property to show or hide secondary (or primary) view controller or set it to .automatic to let it choose the most appropriate layout for the available space.
On my storyboard, I have created 2 view controllers; one for iPhone 5 and iPhone 6. How can I access different view controllers for different phone sizes. Online I found something that let me switch different storyboards but I only want to change one screen. Is there any way I will be able to do this or is making a duplicate storyboard with one different screen the way to go?
I find that size classes are so error prone that I was tempted to use that approach at some point (ended up making all my constraints totally independent of screen size and orientation but that's another, interesting but irrelevant, story).
One way you could do this is using custom segues with a naming convention. Let's say you already have a storyboard segue that links to a view controller for iPhone5 and you want to redirect it to your iPhone6 variant.
Give that segue a name that finishes with ".iPhone5". Then create a custom segue (dragging from the red square of the source viewController to the target one) and give it the same name but with a ".iPhone6" extension.
You can implement override shouldPerformSegueWithIdentifier in the calling controller and, if you're on an iPhone6, respond with false and programatically trigger (performSegueWithIdentifier) the iPhone6 segue using the identifier you received as parameter replacing ".iPhone5" with ".iPhone6".
You could centralize that code in a function or an extension to UIViewController to make it easier to implement on your various view controllers.
I am creating a simple little popup view, similar to the popup that appears when you push the volume buttons. I would like to display an instance of that popup view in different view controllers. I have been pondering a couple approaches, but I would like to know what is the best approach, taking into account MVC, complexity, and otherwise 'good' practices.
Currently, I am creating and displaying this UIView from within my UIViewController. I justified that approach since it's really a small view and I do a lot of work with it to modify its behavior in that VC, so that code was already going to be in the VC. Essentially, I make a frame, set the background, apply corner radius, add text to it, apply motion effects, then make it fade in then later fade out. I could copy and paste the code into my other VCs but that's obviously a bad approach.
I could create a subclass of UIView and I'm sure I could use drawRect to draw it, but I'm not sure exactly how to add that view to the VC exactly in the middle, unless I drag out a view to my VCs and change its class. But if I do that I can do most everything in Interface Builder anyways, which would be preferred especially if I can use Auto Layout to always keep it centered. But, I'd need to copy and paste that UIView into each VC and hide it - that doesn't sound good.
I could create a subclass of UIView and instead of drawing with drawRect, implement a method that creates the UIView and returns it. Then in the VCs I just call that method and add the view it returns as a subview. I've never done this, and I'm not sure if that's an appropriate approach.
What is a plausible approach to implementing such a view that can be thrown on screen from any of my VCs? Thanks!
Note that this view should always be the same size, in the center of the screen, not tied to any specific VC. It should remain on screen unaffected by transitions and such. It closely mimics the Volume popup.
I would like to display that same popup in multiple view controllers.
I expect that you mean you'd like to have separate instances of that same class in multiple view controllers. A given view can have only one superview, so it can't exist in more than one view at a time.
I'm not sure exactly how to add that view to the VC exactly in the middle
It's easy to center a view in its superview. To center horizontally, subtract the width of the view from the width of the parent. Divide the result by 2. That's your X coordinate. Same goes for the Y coordinate, except that you'd obviously use the heights.
An even easier method is to create a point by dividing the superview's width and height each by 2. Set your view's center property to that point.
What is a plausible approach to implementing such a view that can be thrown on screen from any of my VCs?
Don't try to reuse the same view. There's no need for that, and trying to pass it around between controllers will really complicate your code. Just have any controller that needs to display your popup create its own copy.
Remember, views are the interface to the data that's stored in your model -- they can display that data or let you interact with the model, but they shouldn't store app state themselves. Given that, there's no reason that you'd need to use the very same view in more than one view controller. As long as your pop up gets its data from the right place, you can have as many instances of it as you like.
If your popup really is separate from the content of any of your view controllers, another possible strategy is to use view controller containment. You can create one view controller that handles just the "app-wide" stuff, like this popup, and have it load and unload the various other view controllers as it's children. I'd caution against trying this, though -- it's probably more complicated than you need and surely more complicated than you should attempt right now given that you seem to still be getting your sea legs.
It sounds like MBProgressHUD is what you're looking for. FFCircularProgressView might also help.
I have an UISplitViewController base project.
I want to have a different detail View depending the orientation of the app.
Exemple :
In landscape when I select a row in the TableView, I want the detailView to be an UIWebView.
But in portrait I want the detail view to be a complex custom view.
Is it possible ?
Thanks.
See the MultipleDetailView sample project for the basics.
The easiest way to shift views based on orientation is to use a navigation control to push an pop the each orientations custom views in response to changes to orientation. Put the nav code in willRotateToInterfaceOrientation:duration: and the view controllers will pop their views and push the other when the device rotates.
I would say, however, the using two different types of views for the same detail but different orientation will most likely confuse the user. That is not what the interface grammar teaches them to expect. In every other app, it is the same basic view with the same info just adjusted for the change in display dimensions.
You might want to think twice about whether this is a good UI design before spending the time to implement it.
I am trying to implement a split view controller like UISplitViewController on the iPad, but I don't want the left pane to be hidden when the device is in portrait orientation.
So I've created a UIViewController subclass for this in IB and it works fine without any sub-view controllers. Now I'm trying to wrap my head around what is required to setup and manage the two UIViewController objects for the left and right panes. In my app, they are going to both be UINavigationController with a UITableView in them.
I've hit a mental road block about how to set this up and was hoping someone could point me to some sample code or give me a recommendation for architecture here...
The only reason to use the UISplitView controller is the show/hide logic it gets you for free. I would think it a lot easier to simply take the two view controllers (Root View & Detail View) and lay them on a standard UIViewController. You can then manage them more diorectly without overriding the intended behavior of the implemented controller.
THe settings app on the iPad does what you are looking for and I believe this is the approach that app takes.
Good Luck!
is setHidesMasterViewInPortrait still a private Api and the app will get rejected?
Create your UISplitViewController instance and then call:
[splitViewController setHidesMasterViewInPortrait:NO];
The compiler will give you a warning message but it will do what you want. You can get rid of the compiler warning by making a category on UISplitViewController that implements that method.