将UIView的子视图放在其CALayer前面?

7

这个可行吗?基本上,我想给我的UIView添加一个子视图,并使该子视图位于视图层的前面(更具体地说,位于所述层的边框前面)。

当然,我可以通过在视图的父视图上制作两个子视图来实现我想要的效果,一个在另一个上面。但如果可能的话,我宁愿避免这样做。

2个回答

5

我自己也找了一段时间,但我不认为这是可能的。我解决了这个问题,就像你所暗示的那样,将子视图和父视图添加到同一个“容器”Superview中。然后只需要对两个子视图进行排序,使您的子视图在另一个子视图之上以及其边框。


1
我用segue动画解决了这个问题,其中需要sourceViewController在destinationViewController的前面。我必须删除sourceViewController以便重新嵌套它。我的代码如下:
- (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...

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接