簡體   English   中英

從UIScrollView移除子視圖

[英]Removing subviews from UIScrollView

我需要從ScrollView刪除圖像subviews ,並且嘗試從subviews array中刪除,但這是一個不可變的NSArray

如何從subviewscrollviews array中刪除subviews

    NSArray *viewsToRemove = [scrollView subviews];
    for (UIView *v in viewsToRemove) [v removeFromSuperview];

你可以這樣做,

[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];

這將刪除UIScrollView的所有子視圖,但會刪除其滾動指示器:_scrollView.showsHorizo​​ntalScrollIndicator = _scrollView.showsVerticalScrollIndicator = NO; [_scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; _scrollView.showsHorizo​​ntalScrollIndicator = _scrollView.showsVerticalScrollIndicator =是;

for (UIView *v in [scrollView subviews]) {
    [v removeFromSuperview];       
}

迅速

for subview in scrollView.subviews {
    subview.removeFromSuperview()
}

在子視圖上調用-removeFromSuperview。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM