Swift 4 UIButton attach on a View - ios

My problem is the following:
I am practicing in swift 4 and for this I am making an app to show my current position and have a SideMenu.
I have managed to make the lateral menu unfold and close with the + button that is in NavBar, but at the time of add a UIButton to perform other actions the button is superimposed on all layers and does not go with the view.
Attached screenshots of the app, and some views of how I have the storyboard in xcode:
pd: is Swift 4 and the latest version of Xcode

You will need to set your menuView's clipsToBounds property to true it is false by default. When false a view's subviews will be displayed even if they are outside the view's bounds. You're also missing a constraint on your button. Auto layout can determine its x position but not it's y. Add a top, bottom, or centerY constraint.

the button is superimposed on all layers and does not go with the view.
It sounds like the button is probably constrained to View or Google Maps View instead of Menuview, so that the button maintains it's position relative to those views even when Menuview moves. Change the constraints so that the button is constrained to Menuview, and the button should then move when Menuview moves.

Related

How to place any view below any other view which is getting it's position from code

I've created 4 subviews of white color & a yellow one as you can see in reference image I've shared below.
And I've programmatically changed the position of Tabbar from bottom to top just below to navigation bar as you can see in below image (When it is running in the simulator).
Now since I've constraints for that yellow view in image as follow
It is appearing just below to navigation bar but I want it to be displayed just below the Tabbar.
Since Tabbar is getting its position programmatically & other views (including yellow view) are getting their positions from the storyboard.
And since storyboard UIelements are get settled before any other UIelement which are coming from the program or at least get their position from programmatically.
What could be the best way to achieve what I want.
Please refer my storyboard as well to get more understanding. (Refer Below image)
I also want to fit all 5 subviews in the space between tabbar & bottom of the screen. I want to calculate 1/5th of that space & assign this height to each subview. I'd later reduce few pixels to separate them.
Why not add the height of the tab bar to the yellow view's top position? That way, you'd set the constraint something like:
Fajar.top = top + 44
If the tab bar is always visible, then that should work. But of course, if the tab bar only appears at times, you'd probably have to change that constraint programmatically depending on the change ...

Hide Bottom Bar When Pushed through Autolayout

I have a UITabBarController with one UINavigationController holding a UIViewController as root view controller.
when tapping one of the button in the UIViewController, I push a regular chat window UIViewController (with TableView + Input View) end hiding the bottom tab bar. (using the "Hide bottom bar when pushed" flag)
In storyboard I added a regular UIView subclass to VC that look like a bottom bar, and I use Auto Layout to pin it to the bottom of the VC view.
The problem
when I push VC it takes a second for this view to pin to the bottom, it looks like auto layout pin it to the bottom as if the tab bar is not hidden and after a sec it recognise that the tab bar is hidden and moves it to the real bottom of the view.
For clear info check this screen shot
Now I will let you the know the constraints of the table view..
Now I am showing the constraints of the InputView
I am also adding my View hierarchy...
I had a similar issue in my project. I solved it by selecting the view I wanted anchored to the bottom (in your case, the input view), held Command, and selected its superview (both views should be highlighted now).
Then I selected the align button at the bottom of IB:
And added a Bottom Edges constraint.
What I had done initially is used the pin menu to pin the view to its superview, but it appears that will pin it to the bottom layout by default, which causes that weird movement during the transition.
EDIT:
After seeing the latest screenshot, the problem could lie in one of the superviews. I'm assuming that chatWindow is a UIView, and your Scroll View is horizontal only. Here's what your should check:
chatWindow is pinned to the scrollView's bottom similar to what I've outlined above.
scrollView is pinned to its superview as I've outlined above.
Moving the inputView outside of the scrollView to the root superview. Then one by one move it down the hierarchy towards its current location.

IOS 8 Interface builder UITableViewCell alignment

I am working on IOS app which got a UITabeView. I needed custom UITableViewCell, so i created .xib file to design it and linked it to my custom class. But I want a button to be aligned right and I cannot achieve it. The screenshot below shows my problem:
I am using autolayout. On the left side I have my .xib opened where I have a button. In the middle there is a simulator which show only a part of a button. Moreover, If a change orientation, absolute button position doesn't change (it becomes fully visible). On the right side you can see how I set constraints. Obviously, I did it in a wrong way, but I've tried everything and nothing helped. Different constraints, values, toggled autolayout - no effect.
How do I set up constraints so that my button is aligned right (on both orientations)?
P.S. I am using Swift.
you have to link your button to the view which contains it, you can press Ctrl and drag the mouse from your button to the view which contains it, Xcode will show a menu with the available constraints:
You have to select the constraints you need for setting up the position of the button, in your case it will be leading space to container, and in addition you should select width and height constraints. For selecting those constraints you can press this button on the bottom of the screen:
and in the following menu select the width and heigth constraints:
Hope it helps!

How do I make a button slide to reveal like the UITableView delete confirmation button?

I would like to re-create the animation of the delete confirmation button that Apple uses in the default implementation of UITableView. I want to create this button and animation in my own custom view area, but haven't been successful in finding a proper view transition or animation. Here is a picture of the reveal animation half way through:
And here is a picture of the animation after it has finished:
These are screenshots from a YouTube video that shows how the button animation is supposed to look.
Thanks!
Basically,
1) Put a button inside a view of the same size as the button, with the autoresizing masks of the button set to force it to not shrink when the view changes size, and have a left flexible margin.
2) Animate the view's frame to change from 0 width to full width while moving from x origin to (x - view width) origin.
As the view grows the button will be revealed. The view should have clipToBounds set to yes.

iOS : How to create a close button that sits on the edge of a UIView with rounded corners (using IB)?

Background:
I am working on an iPad app that will pop a custom view when the user clicks on an image.
I want the view to have rounded corners and a close button ( red x in a circle ) that sits on right top edge.
The button in half inside and half outside the view.... Take a look at the Kayak or Zynga Poker apps to see what I am talking about.
Question : If I create the view programmatically and add the button, it works.
However, I really want to user a nib to create the view so I can design the view correctly. So when I call self.layer.maskToBounds = YES on the view ( to create the rounded corners with a radius of 25 ), it clips my button ( since its half in and half out ). How do I retain my button without it getting clipped and still have rounded corners ?
Sounds to me like you are using a view and a button. What you might try is using a third container view (with clear background) in which you place your original view and your button. The button will need to be on top of the view, so to speak, so it is not obscured by your view. But that should allow you to have properly rounded corners on your view (not the container view) and have your button fully visible.
Some settings, such as maskToBounds, cornerRadius, aren't available in IB. You can create the entire view using a NIB except it won't have rounded corners in IB and in viewDidLoad you set just those properties that couldn't be set in IB.

Resources