如何在父视图中获取子UIView的索引? [英] How can I get the index of sub UIView in the parent view?

查看:202
本文介绍了如何在父视图中获取子UIView的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 exchangeSubviewAtIndex:与SubviewAtIndex:方法一起使用.

I want to use exchangeSubviewAtIndex: withSubviewAtIndex: method.

但是如何获取这些视图的索引?我已经有了他们的指针,所以我认为可能有一个类似的方法.

but how can i get the indexes of those views? i already have their pointers, so I thought there might be a method like.

[parentView indexOfSubview:subview];

但是我在Xcode文档库中找不到这种东西.

but I couldn't find that kind of thing in Xcode documents library.

请帮助我!预先谢谢你.

please help me! thank you in advance.

推荐答案

获得方法如下:

[parentView.subviews indexOfObject:subview];

在Swift中:

parentView.subviews.firstIndex(of: subview)

这篇关于如何在父视图中获取子UIView的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆