Why is my UIView drawing behind my other views? - ios

I have a UIView which is opened and closed by a button onscreen. I am positioning it over a scrollable custom text area which is a bunch of UILabels added to a UIScrollView.
I've made sure that it is added last in my view hierarchy, in the xib. I have also tried calling bringSubviewToFront, and have even removed the UIView from the parent view and re-added it after doing the layout.
Nothing that I have tried prevents it from being drawn behind this UIScrollView. I have verified that my UIView is actually the last UIView in the hierarchy by looking at the view hierarchy in the debugger at runtime.
The UIView in question, shown as a smiley in the picture here, has children. It has a 3x3 grid of invisible UIButtons, and a UIImageView to draw the image, which is normally something other than the smiley. But I am operating on the parent UIView, not the children.
Is there anything I can try, to help diagnose this? To recap, I have done all the following:
the UIView is added last in my view hierarchy, after the UIScrollView. It is a child of the same parent (the root view) as the scroll view - hence, a sibling view of the scroll view.
after doing the layout, I've tried [self.view bringSubviewToFront:myView]
after doing the layout, I've tried doing [myView removeFromSuperView] followed by [self.view addSubview:myView].
The latter two operations are performed at the very end of my layout method.
Any ideas?

Related

Hide non child UIView in UIView

I want to hide a non child UIView in a UIView but I don't know how to do it.
To be specific, I have a UITableView. Each UITableViewCell has another view inside it (a wrapper view called wrapperView). The wrapper has some labels set up in IB and some created programmatically. I have created a custom slide mechanism that reveals buttons under the wrapper (like the standard one does).
The labels created programmatically don't exceed wrapper's bounds because it clips the subviews. The problem is with the labels created in IB. They are the subviews of contentView.
How can this be solved? Is there a way for a UIView to clip other views on the same level(not parents nor children)? Or "transfer" the labels to the wrapper view?
It isn't completely clear what you're asking. A view will only clip it's subviews, not views that happen to fall within their frame rectangle but aren't subviews.
If you want to move a view object from one view hierarchy to another you can use addSubview(_:) to do so. That will automatically remove it from it's current parent view. To quote the Apple docs:
Views can have only one superview. If view already has a superview and
that view is not the receiver, this method removes the previous
superview before making the receiver its new superview.

Content in UIScrollView is being cutoff early

I have several UIViews within aUIScrollView and I want them to scroll all the way to the bottom of the UIScrollView before cutting off (See Image #2).
Background on the scroll view:
I created the UIScrollView itself is a subclass of a customUIView. I put the view in a UIScrollView so the auto layout in storyboard creates the correct frame for the device.
In the view controller attached to the storyboard UIViewController I created anIBOutlet to theUIView, and in the viewDidAppear function I called a function attached to the view that populated the UIScrollView.
In the storyboard I gave the view a blue background so I could tell its frame. Here is the what the storyboard looks like:
Then this is what it looks like on my phone:
Notice how much space exists between where the view cuts off and where the bottom of the screen is. It does this on all devices.
I have tried adjusting the bottom content inset. It is currently at 0.0 but I tried to make it -20 and that did not help.
How can I fix this?

Animating UIView with auto layout when the view is just created and about to appear

I have a UIView that contains subviews that contains subviews...(Hierarchy of UIViews).
Every UIView is set with auto layout. When I press a button, this UIView is created and then I would like it to drop from the top of the screen.
The problem when I use layoutIfNeeded in an animation is that if will animate everything at the same time as it is a newly created UIView (not yet display).
My question is, is there a way to do the animation of only the UIView dropping with all the subviews already laid out in it?
I guess you can do it by creating the UIView when UIViewController displays and then hide it but I was wondering it there was another way.
Cheers
If you call layoutIfNeeded right after you add it to a view, while still outside the view, it should lay out it's views correctly. And then in the animation you call it again so the view animate to the final position.

UIView overlaps UISegmentedControl

In my app, I want to add a UISegmentControl on top of a UIView.They are siblings of a parent UIView.I pull a UIView to the canvas from object library first, and then pull a UISegmentControl second,but unluckily the first added UIView overlaps the UISegmentControl. What I want is that UISegmentControl is on top of the UIView. I mean UISegmentControl z-index is higher than the UIView.
The following is the screenshot.
One potential solution would be to programmatically send either the UIView to the back or the UISegmentedControl to the front in viewWillAppear(animated:) using parentView.bringSubviewToFront(segmentedControl) or parentView.sendSubviewToBack(otherView). It doesn't solve the issue of the incorrect appearance in your storyboard but it ought to fix the issue once the app is running.
1) First reduce the width and height of the overlapping view to understand its location in view hierarchy. Share your view hierarchy here so we can see in detail.
2) Delete everything from storyboard. Add UIView and then add any subviews. These 2 controls should be children of UIView in view hierarchy.

How can I bind a UIView's orientation to that of it's parent view?

I have a UIViewController, with a toolbar at the top. I have a few views that I'm going to be adding and removing, but I don't want them to cover up the toolbar. So I made another UIView, that fills the area beneath the UIToolbar, and am adding views thee, and it works great.
When I rotate the device though, the first subview rotates with the view controller, but the UIView inside of the UIView thats inside of the UIViewController doesn't rotate!
What can I do to make it rotate with the parent UIView?
PS- If you can think of a better way to do what I'm trying to do, I'm all ears!
EDIT:
To clarify, I have a UIView subview in IB, and that is all hooked up to the code just fine. Then, depending on the button selected, that UIViews subviews are removed, and then a new one is placed in the subview array. So I use addSubview to and removeFromSuperview to add/remove the view from the UIView that is a child of the UIViewController view...

Resources