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.
Related
I'm trying to implement sth like images below. there are some views that should be displayed in a sequential order and a bar above them shows the flow of tasks.
as it is shown, first profile view should be displayed. when the user clicks on Go to Next View Button second view (price view) should be displayed. the top bar shows the current view where we are in it. I've tried PagingMenuController already to create a menu with views and then disable scrolling. but PagingMenuController loads all views at the same time and also i don't know how to go to next menu item within child views. now I'm thinking of a container view might be helpful but i didn't use container view so far and i don't know it's good for my purpose or not.
also i want that top bar without swiping between views (only on buttons) and one enable view at the same time.
any helps would be apprectiated.
Your question is both broad and vague. My answer is also going to be fairly high level. I suggest you follow my outline, and if you get stuck on a particular step, post your code, tell us about the problem you're having, and we can help you fix it.
This is pretty simple. Create custom view controller. Give it a container view at the bottom that would contain the current child view controller. Use view controller transition methods to switch between child view controllers. You'll want to add layout anchors to each new child view controllers to pin all of it's view's edges to the edges of the container view.
Create a custom control on top to show the dot and highlight the title of the current view controller.
If you want the next/previous buttons to be on the child view controllers, put them there, and add a delegate property to all the child view controllers that points to the parent view controller, with next and previous methods.
BTW, in languages, like English, where text is laid out from left to right, I would think your first page would be on the left and the last page would be on the right. (I think it makes more sense for profile to be on the left and pay on the right.)
I followed this blog post that explains how you can implement a custom UINavigationBar that has an increased height, if for example you wanted to put additional ui elements in the nav bar underneath the rest of the bar content that will persist between navigation on the stack. This code works really well in the case where you always want it to be that increased height.
In my app, I need to start the navigation bar at its default height, then increase it later, adding more content, after the user performs a given action. Very similar to the song info and controls in the iTunes Store:
So I put some checks in place to not reposition anything if a BOOL property is NO. When I set it to YES, I call [self setNeedsDisplay] which will call layoutSubviews to position everything appropriately based on that boolean value. sizeThatFits is also called and I return the proper height.
The problem is, I can't call [self setTransform:CGAffineTransformMakeTranslation(0, -(NavigationBarHeightIncrease))]; in initialize. Instead I call that at the same time I change the boolean value to YES. Because of this, all of my elements are moved up that amount. But if I don't call setTransform, the elements in the nav bar are in the proper position, but the bar itself is positioned too far down, so that the custom view I've added to the bar is shown overtop the view controller's view - it bleeds out, and the extra space I added is black not the navigation bar's background color.
If I call setTransform in initialize, when the height is the default height, the elements are moved up when they shouldn't be.
So, how can I properly dynamically change the height and positioning of a UINavigationBar subclass?
As suggested in the comments, to achieve the behavior where a custom navigation bar (not subclassing the native control) persists across pushes and pops of controllers in a navigation controller, you'll need to have a single controller with the custom navigation bar and then a single embedded view that resolves to a UINavigationController with its view controllers underneath. Then, it will also be necessary to set the navigation controller's delegate to the root controller so that the title and other properties can be updated as the sub-controllers are pushed and popped. I've provided a screenshot below of what the storyboard version of this might look like:
An option is to create a UIViewController in storyboard which has only the control view you wish to show below the navigation bar with everything else transparent. The advantage here is you design this using the normal tools. Use constraints to place it just below the navigation bar and to set the heights, widths etc of your views.
When you wish to show the control, you can create an instance of this UIViewController and remove the content view from it and add it to the view hierarchy of what is on screen.
There are two options for inserting the extracted base view:
If you add this control view to the view controller at the top of
the navigation stack (what is on screen), it would be covered when
you push on a new controller. This is not what you said you wanted.
If you add this control view to self.navigationController.view, then
it will persist across pushes and pops. This is what you said you wanted.
I use this approach to provide popup help bubbles to describe what is on screen. Depending on whether I use option 1 or 2, I can persist help across multiple pushes/pops.
I got the idea from this tutorial which describes the general approach: http://blog.typpz.com/2013/12/09/ios-sdk-create-a-pop-up-window/
That link provides a full code example on how to bring up the view and remove the view.
This would let you design it in IB, present and dismiss it as required and persist it across navigation sequences.
Hope this helps.
I'm trying to upgrade my app to use Autolayout, basically to be future-proof, but I'm running into a huge amount of problems TRYING to use autolayout.
What I have is a view controller which contains two UINavigationControllers (using view controller containment). If I press a button, I want the menu to come down. Within the menu, i'll push view controllers and whatever else, and if the user wants to quickly get out of the menu they can tap the bottom part of the view at the bottom. Basically, if you've used Uber, something similar to that.
I have fiddled and fiddled but I can't get it to work correctly. The best I got was set up a XIB for the container view, and have two views within it (as well as a few outlets for some constraints). Within code, I change the constants of these constraints to make the menu view move and to force the correct height of the menu (which is the same as the bottom minus an offset).
The problem comes in when I try to push another view controller in the menu as it seems to throw away the height constraint set on the menu -- new view controllers take up the entire screen. I don't want to use clipSubviews because that doesn't really solve the problem, and sometimes I use overlays which need to go outside of the view.
To be honest, I don't even really care that much if this animation even uses autolayout, but I want to be able to use it on the view controllers within each navigation controller. Right now, if I turn it on, the animation won't work at all.
Any ideas?
I know, this seems a bad solution, but I can't think or figured out how to make something better.
What I need to do is like a menu, iPad menu, with a toolbar up and bottom, and an image in the background. In the bottom toolbar, I'm going to have 4 different buttons. Every button is going to create the options menu in the middle of the screen. One button needs to display 3 options (buttons with images), another 4 options, another 8 options (for this, I'm going to use Scroll View and Page Control, because I'm going to need 2 pages), another 2 options.
I was trying to use subviews, one subview for every button, and I was added the options in the subviews. When I select one button, its subview was loaded, but when I tried to change its position and size, its buttons was missed, the subview was empty...
Now I'm going to have the 4 subviews in the ViewController, but hidden. When I select one button, the view is going to appear, and the others views are going to have hidden. This means, that all the subviews are going to have loaded. Is this convenient?
Is this method requires a lot of memory?
If somebody have another and better solution, I'll be completely grateful...
Thanks
Yes, you can have multiple hidden subviews within a view controller, but I don't think it's the most practical way of going about it.
You mention that the menus are to appear in the center of the screen. In this case, I think a better approach would be to create a separate view controller for each of your menus and then have your main view controller present them modally by using the view controller's modalPresentationStyle property. By doing this, you're saving yourself a ton of time by not having to write code that checks for which views are hidden and which aren't; you're letting the API do its job, so at most you'll need to implement a few methods such as dismissModalViewControllerAnimated:.
Check out Apple's documentation about UIViewController, and more specifically the section called "Presenting Another View Controller's Content".
I'm trying to create a form sheet modal on iPad, which should be a 540x620 modal view.
I've created a view controller with a NIB file whose view is a 540x620 sized UIView (with stuff on it).
I set the modal presentation style to UIModalPresentationFormSheet, and call presentModalViewController:animated: on the current view controller.
My view slides in from the bottom, but instead of being a form sheet, it takes up the whole screen (my view elements are all anchored in the top left of the screen).
Even stranger, when I dismiss it, all the UI that was "underneath" it, is all re-layed out to be in the center, in approximately a form sheet sized area in the center of the screen. Bizarro!
Anyone have any suggestions as to what could cause this behavior?
Thanks.
Figured this out. I was setting the modal presentation style on the parent view controller-- it needs to be set on the newly-created child controller. One needs to think of it as a property of the child, not something the parent controls.
I would delete this question, but figure I'll leave it as a signpost for the future wayward.