put subviews of a UIView in front of its CALayer?

落爺英雄遲暮 提交于 2019-12-04 03:22:48

问题


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.


回答1:


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.




回答2:


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...

}


来源:https://stackoverflow.com/questions/6551394/put-subviews-of-a-uiview-in-front-of-its-calayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!