Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

put subviews of a UIView in front of its CALayer?

Is this possible? Basically, I want to give my UIView a subview, and have that subview be in front of the view's layer (more specifically, in front of said layer's border).

Of course I could achieve the effect I want by making two subviews of the view's superview, one on top of the other. But I'd rather avoid that if possible.

like image 354
William Jockusch Avatar asked Jul 01 '11 17:07

William Jockusch


People also ask

What is the difference between UIView and CALayer?

Working with UIViews happens on the main thread, it means it is using CPU power. CALayer: Layers on other hand have simpler hierarchy. That means they are faster to resolve and quicker to draw on the screen. There is no responder chain overhead unlike with views.

How do you bring a view to the front?

Just one single method will let you to bring your view to the front and the magic words are : myView. bringToFront(); “.

What is the layer property on a UIView object?

All UIView subclasses have a layer property, which is responsible for drawing their contents efficiently. These layers are powered by Core Animation, which handles all the drawing and animation that UIKit requests.

What is a Subview Swift?

"subviews" means the views which are holding by the curent view. For example, you have a view (will call it as MyView) which include a button. Button is a view too (UIButton is a kind of view). So, MyView is superview for the button.


2 Answers

I looked for this for a while myself; i don't believe it is possible. I solved the issue by, as you hint at, adding the subview and the parent to the same 'container' superview. Then its just a matter of ordering the two subviews, so that your subview is above the other and its border.

like image 118
cheekoli Avatar answered Oct 18 '22 07:10

cheekoli


I solved this with a segue animation where i needed the sourceViewController to be in front of the destinationViewController. I had to remove the sourceViewController in order to re-nest it. My code looks like this:

- (void) perform {

    UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
    UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
    UIView *parent = sourceViewController.view.superview;
    [sourceViewController.view removeFromSuperview];
    [parent addSubview: destinationViewController.view];
    [parent addSubview:sourceViewController.view];

    // Perform animation stuffs...

}
like image 20
Deminetix Avatar answered Oct 18 '22 07:10

Deminetix