xcode – 关于bringSubviewToFront

前端之家收集整理的这篇文章主要介绍了xcode – 关于bringSubviewToFront前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用以下代码将控件带到前面:

[self.view bringSubviewToFront:control];

如何在两个控件之间识别;哪一个在前面,哪一个在后面

解决方法

您将检查superview(在控件中,在您的案例中为self.view) subviews属性中的视图顺序.

superview子视图中索引0处的视图是最后面的视图,然后索引1处的视图将位于其顶部,索引2处的视图将位于索引处的视图顶部等
(基本上视图位于视图之上,索引与其自己的索引相比较小)

NSInteger indexOfControl1 = [[self.view subviews] indexOfObject:control1];
NSInteger indexOfControl2 = [[self.view subviews] indexOfObject:control2];
if (indexOfControl1 > indexOfControl2) {
    //control1 is on top of control2
}

猜你在找的Xcode相关文章