我需要从ScrollView
中删除图像subviews
,我尝试从subviews
的array
中删除,但那是一个不可变的NSArray
。
如何从scrollviews array
的subviews
中删除subview
?
我需要从ScrollView
中删除图像subviews
,我尝试从subviews
的array
中删除,但那是一个不可变的NSArray
。
如何从scrollviews array
的subviews
中删除subview
?
NSArray *viewsToRemove = [scrollView subviews];
for (UIView *v in viewsToRemove) [v removeFromSuperview];
你可以这样做,
[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
这段代码会删除UIScrollView的所有子视图,但保留其滚动指示器:
_scrollView.showsHorizontalScrollIndicator =
_scrollView.showsVerticalScrollIndicator = NO;
[_scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
_scrollView.showsHorizontalScrollIndicator =
_scrollView.showsVerticalScrollIndicator = YES;
[_scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
将删除所有UIScrollView子视图,包括其滚动指示器。在从scrollview中删除所有子视图之前隐藏滚动指示器将确保不会从scrollview中删除滚动指示器。 - calinbfor (UIView *v in [scrollView subviews]) {
[v removeFromSuperview];
}
在子视图上调用-removeFromSuperview。
Swift
for subview in scrollView.subviews {
subview.removeFromSuperview()
}