本文介绍了从UIScrollView中删除所有子视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从UIScrollview中删除所有子视图?
How do I remove all of the subviews from a UIScrollview?
推荐答案
让 scrollView
是 UIScrollView
的实例。
在Objective-C中,它非常简单。只需调用 makeObjectsPerformSelector:
,如下所示:
In Objective-C, it's pretty easy. Just call makeObjectsPerformSelector:
, like so:
Objective-C:
[scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
在Swift中,您没有获得运行时访问权限,因此您必须自己实际处理迭代。
In Swift, you don't get that runtime access, so you have to actually handle the iteration yourself.
Swift:
简洁版,:
scrollview.subviews.map { $0.removeFromSuperview() }
更具描述性的方法(来自)假设 scrollview.subviews
:
A more descriptive way to do this (from here) assumes scrollview.subviews
:
let subviews = self.scrollView.subviews
for subview in subviews{
subview.removeFromSuperview()
}
这篇关于从UIScrollView中删除所有子视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!