I always heard to set constraints to kind have a distance from view to view, but i would like to know if it is possible to set a view to invade another one.
My problem is, if you look on the image, you see 2 views, a soccer ball and a big white square.
Final result would be like this:
I would like to set a constraints to be like the image, the ball always get some space inside the white square view, it is possible to do something like that or i just need to go on paint, photoshop, or some other software to create an image like i pretend to have and don't worry about constraints anymore (like a work around).
This can be done with basic auto-layout -- there is absolutely nothing wrong with constraining views so they overlap.
Here's a quick example:
Note the last constraint in the outline on the left:
BoxView.top = ball.bottom - 24
That puts the bottom of the image view 24-pts below the top of the "box" view... in other words, it has a 24-pt "overlap."
Edit
By swapping the constraint order, it may be a little more clear:
Now, the last constraint shows:
ball.bottom = BoxView.top + 24
which may be a little more intuitive.
Edit 2
Regarding your comment - that the ball image view is covered by the grey box view...
I cannot replicate it, but I've seen this happen before with image views. Even using Debug View Hierarchy
shows the image view in front of the other view, but it gets rendered as if it was behind it. In the cases where I've seen it, re-making the controller in Storyboard has fixed the issue.
However, it might not, so...
Assuming you have the image view connected to an outlet, you can try this:
@IBOutlet var ball: UIImageView!
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
view.bringSubviewToFront(ball)
}