[英]Removing subviews from UIScrollView
I need to remove image subviews
from a ScrollView
and I tried removing from the array
of subviews
but that is an NSArray
which is immutable. 我需要从ScrollView
删除图像subviews
,并且尝试从subviews
array
中删除,但这是一个不可变的NSArray
。
How can a subview
be removed from the scrollviews array
of subviews
? 如何从subview
的scrollviews array
中删除subviews
?
NSArray *viewsToRemove = [scrollView subviews];
for (UIView *v in viewsToRemove) [v removeFromSuperview];
你可以这样做,
[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
This will remove all subviews of a UIScrollView but its scroll indicators: _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = NO; 这将删除UIScrollView的所有子视图,但会删除其滚动指示器:_scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = NO; [_scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; [_scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator = YES; _scrollView.showsHorizontalScrollIndicator = _scrollView.showsVerticalScrollIndicator =是;
for (UIView *v in [scrollView subviews]) {
[v removeFromSuperview];
}
Swift 迅速
for subview in scrollView.subviews {
subview.removeFromSuperview()
}
在子视图上调用-removeFromSuperview。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.