Creating an animated slide-down menu using Autolayout - ios

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?

Related

how to manage view controllers in a sequential pattern - swift

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

How to implement swipe views with CollectionView/TableView Controllers?

I am creating an app using Swift, and I'm still trying to figure out what the best configuration would be.
What I'd like to have is 3 screens (the left screen would have a side out panel) that users can access via the navigation bar menu or just by swiping left/right the screen for more accessibility.
I could easily create my TableViewControllers/CollectionViewController and the menu, but I'm struggling at making the screen able to detect users gestures at the same time, and I'm not sure whether I should use 3 View Controllers and then add the Collection View/Table View via the Storyboard, or directly use the CollectionViewController/TableViewController
I added a picture here describing what I'd like to accomplish:
Also, I wonder whether I should use storyboards or not for my project.
I know that's a lot of questions !
Any ideas please ?
Thank you very much and have a good day,
J.
You need to add 2 "swipe gesture recogniser"s to your middle screen(your second screen in your attached image) , and set one for identifying left swipe and another for right swipe. Create action methods for both in your view controller and add code accessing left screen and right screen in respective methods.
note - you need to drag "swipe gesture recogniser" to top bar of your view controller scene to add it.
You can use a scrollview as a container, put three ViewController in it.

How do I make a now playing bar like in media player apps in iOS with XCode?

I am making a media player app. I have UITableViewControllers that are embedded in Navigation Controller. I would like to somehow make a view that would overlay potentially multiple (2?) of these tableviewcontrollers (one that shows the user's playlists, and the next would show the tracks in the playlist), but only at the bottom, like a now playing bar in (e.g.) Spotify's iOS app (as in the left bottom side of this
or as in this
I have tried to drag a Container View into my Navigation controller (in which my TableViewCell is embedded), but it won't let me drop it there.
It looks like I can drag the Container View into my TableView, but then how would it remain there when i navigate between tableviews?
Trying to follow #Rintaro's suggestion, but I'm a little new to XCode. How did you do this? So I made a single view application, i added a container view to the first VC, it's imm drawing it somewhere else in the storyboard, but i can't figure out how to tell that view that it's a navigation controller. also, as soon as i add a second container to the first VC and tried to size it, the first container disappears! It is still listed in the hierarchy on the left, and still has an arrow pointing out of it, but the view controller that was added and was being pointed to is also invisible?!
UPDATE: This works very well, but it has a problem with orientation changes. how can i make this work in both orientations? (I hypothesize that it currently positions the "nowplaying view" off screen when the orientation changes).
Basically, view hierarchy like that is constructed like this:
Using two "Container View" in initial view controller, one for Navigation Controller, one for "Now Playing Bar" view controller.
ADDED:
"Main Container View Controller" would be your own UIViewController subclass. It will have responsibility to show/hide "Now Playing Bar".
Workaround for Interface Builder strange behaviors.
You can set Auto Layout constraints like following. Maybe you might want to select the view from the left menu.
Note that, you should uncheck Constrain to margins check box.
Container View for Navigation Controller:
Container View for Now Playing Bar Controller:
And then, Update Frames from the menu:
If you are manually placing any buttons with absolute coordinates, make sure that you update the coordinates of them when the rotation is changed.
Obviously you need to create a custom UIView class, where you will show this menu. And when you will create it, add it to your view just like here:
float y = ROOTVC.view.frame.size.height - 49;
[self setFrame:CGRectMake(0, y, 320, 49)];
[ROOTVC.view addSubview:self];
[ROOTVC.view bringSubviewToFront:self];
I would simply add a nowPlayingView to the appDelegate.window and adjust either:
The window.rootController.view frame to avoid overlapping the nowPlayingView.
If window.rootController.view is a UIScrollView, adjust its contentInset.bottom to avoid overlapping the nowPlayingView. You can also use transparency/translucency with this solution.
Add a dummy toolbar to the controller that will get covered by the nowPlayingView.
If your window.rootController is a UINavigationController, then you have to probably do the above fore each controller you push. The nowPlayingView will stay unchanged on top.

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.

Can I Have Multiple Hidden Views In A ViewController?

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".

Resources