How show view overlay another view and change view size - ios

How to achieve below task?
Explanation:
I want to show collection view over main view. Collection view must shown on half screen and change size to full screen by gesture(drag or swipe).
Please help me. How can I do that?

I think. I must use modalPresentationStyle and transitioningDelegate.
for half screen user UIView.animate with
CGRect(x: 0, y: containerView!.bounds.height / 2, width: containerView!.bounds.width, height: containerView!.bounds.height / 2)

Related

Creating a view permanently underneath UINavigationBar

My issue is that i need to have a single view just below the UINavigationBar on screen at all times whilst navigating through a sign up journey. This is to display the current step in signing up. This needs to stay on screen at all times as the stages animate as they change so simply pushing a new view onto a UINavigationController isn't sufficient.
See an example of what i need to achieve below
I need to have the red item persist at all times even when a new view controller is pushed on
To try fix this I have created a custom UINavigationController in order to have a sticky view be present regardless of what view controller is showing.
I have created this code which suits my needs however doesnt feel like the correct option. Especially as I need to support iOS 10 and additionalSafeAreaInsets is not available
override func viewDidLayoutSubviews() {
stickyView.frame = CGRect(x: 0, y: navigationBar.frame.maxY, width: view.frame.size.width, height: 60)
children.forEach { $0.additionalSafeAreaInsets = UIEdgeInsets(top: 60, left: 0, bottom: 0, right: 0) }
}
What would be a good way to make sure that the view controllers frame starts below this header view? Or maybe an alternative approach?
There seems to be very little stuff on this topic from what i can see on stack overflow

Using MultipleView controller in Container view

I am building an iOS app which have its many different views and difficult also.
I have a tab bar with 4 pages that are as under
Account
Main Page
Wallet
My Lists
when User will tap on List (4th num option), my app needs to show a Header with segmented control (or any top bar like control not decided yet) I want to move Multiple ViewController here . let say top bar has 5 buttons as under
Home list
Relative list
Friends list
office list
clients list
For these different list I have made different View controller. that I want to move in the My List (which is Main view controller and will be deal as a Master view controller and will contain above mentioned 5 buttons) In this Master view controller when I click Home list or Friends list button it will move related View controller just below this top bar (button list)
For more clarification see the picture below. And just let me know How can I do this. . How can I make specific area to be taken by child View controller.
Well I think you are a little confuse in using Container view using IB or by programmatically. when You use in IB , you have to simple create a related class for it. Just like You create View Controller by dragging from Object library and associate it with coca touch UIViewController class.
I will suggest to watch this tutorial. its quiet simple and easy to understand.
but the answer of your question is:
Take a UIView just below the top bar as you said in question. You can make it full width and full height however you like. Then create its out let. just like below and use this as
#IBOutlet var viewMain: UIView!
and just move your Child view controller with this
viewMain.addSubview(childViewController)
You are done
If SegmentControl views have same design then you do not need separate ViewControllers for each.
If Each list has totally different UI then there are many ways to do this.
1- Use scrollview,its content width will be Screenwidth * number of views.
Just add all the views in scrollView.
For Example you want to add to two views Here is the code
self.scrollView.contentSize = CGSize(width: UIScreen.main.bounds.size.width * 2, height: self.scrollView.frame.height)
let vc1 = your view controller
vc1.view.frame = CGRect(x: 0, y: 1, width: scrollView.frame.size.width , height: scrollView.frame.size.height)
let vc2 = your second viewcontroller
vc2.view.frame = CGRect(x: UIScreen.main.bounds.size.width, y: 1, width: scrollView.frame.size.width , height: scrollView.frame.size.height)
scrollView.addSubview(vc2.view)
scrollView.addSubview(vc1.view)
Now if you want to change visible view
scrollView.scrollRectToVisible(CGRect(x: UIScreen.main.bounds.size.width * CGFloat(//Position of your view 1 or 2), y: 0.0, width: UIScreen.main.bounds.size.width, height: scrollView.frame.size.height), animated: true)
2- Use Containers
3- There are very good open source libraries(pods) available as well.One one them is CarbonKit
https://github.com/ermalkaleci/CarbonKit

iOS Swift Setting View Frame Position Programmatically

I having two sub views inside scrollview. I need to position that both subviews programmatically. I did it correctly by writing code inside DispatchQueue.main.async. Here is the code:
DispatchQueue.main.async {
self.SelectClientDetailView.frame = CGRect(x: 0, y: 637, width: self.SelectClientDetailView.frame.size.width, height: self.SelectClientDetailView.frame.size.height)
self.SelectClientDetailView2.frame = CGRect(x: 0, y: 837, width: self.SelectClientDetailView2.frame.size.width, height: self.SelectClientDetailView2.frame.size.height)
}
Its working good but when I scrolling my scrollview this both views set back to old positions. How to fix it. Its Default y position will be SelectClientDetailView:400 and SelectClientDetailView2: 600
If you are using Auto Layout then setting frame will cause some weird effects. Auto Layout and Frames doesn't go together. You'll need to rearrange the constrains, not the frames. While using Auto Layout changing the frames will cause some weird effects and will eventually revert back to the constraints you've created in the original UIView.
Some solutions:
If you want to use Autolayout approach then, You need to create an outlet to each constrain just like you would to a view and change its constant when needed.
disable Auto Layout in that specific xib and start playing with frames.
If you only want to change the frame Y position, try this instead:
self.SelectClientDetailView.frame.origin.y = 637
self.SelectClientDetailView.frame.origin.y = 837
As already mentioned, you might need to check your view hierarchy to be sure you are actually adding them to the UIScrollView (and not elsewhere).

Swift - SWRevealViewController menu placed after the status bar

I'm using SWRevealViewController menu and I have a header view for the table. You can see the table controller view structure and constrains:
And this is how my menu looks like
but I need it to be like
I tried :
self.profileHeader.frame = CGRect(x: 0, y: -20, width: profileHeader.frame.width, height: profileHeader.frame.height + 20)
But nothing changed.
Try using a normal UIViewController, and adjust constraints for the tableView manually check top constraint linked to view and not to top layout guide.
I hope this helps you, let me know about

How do I create a new View (or subView) with the tap of a button in swift?

I am currently making a flashcard app, and I am trying to make a button that creates an entirely new View (or subView) for the user to edit. Should I use Container Views? Collection Views? I also want to have these set to only one View Controller, so I can save the "cards" in one "set". Please Help!!
Edit: How can I save these views in a "folder" so the user can look at them later. Is there an efficient way to do this so the app doesn't slow or stop.
Edit #2: Ok, so I'm kind of getting it... collection views. But how would I implement this into my because I am using tvOS. Any thoughts?
If you want to create a new UIView programmatically, it's actually quite simple. You could create a method like this:
func addNewView(to container: UIView) {
let newView = UIView()
container.addSubview(newView)
newView.backgroundColor = UIColor.blue
newView.frame = CGRect(x: 10, y: 50, width: 200, height: 250)
}
That would create a new view inside whichever container view you passed in with a blue background, 10pts from the left (x-axis), 50pts from the top (y-axis, think a normal cartesian coordinate system with the y-axis inverted), width of 200 and height of 250.
You could then call this method on the push of a button by handling a button tap with it's own method like this:
func buttonTapped(_ sender: UIButton) {
addNewView(to: self.view)
}
Obviously all the values for the frame I gave you were just for an example so you could visualize it in your head, you can edit those however you want, or make calculations based on the size of your device's screen. You can get the device's screen size by saying self.view.bounds

Resources