有時候必須要移除所有子視圖 (Remove All Subviews),再來產生新的子視圖,除了可以回復原始狀態外,管理起來也挺方便的!

其實有很多寫法,就看怎麼寫比較俐落,未來回來讀code,就可輕易理解。
/**
Theme: Remove All Subviews
IDE: Xcode 9
Language: Objective C
Date: 106/12/01
Author: HappyMan
Blog: https://cg2010studio.com/
*/
// 原本使用
for (NSInteger i = [lineScrollView.subviews count] - 1; i > 0; i--) {
UIView *view = lineScrollView.subviews[i];
if ([view isKindOfClass:[UIImageView class]]) {
[view removeFromSuperview];
}
}
// 現在使用
[lineScrollView.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)];
我的目的就是重新生成紅色的波形圖,讓它可以持續從右往左移動。
參考:What is the best way to remove all subviews from you self.view?。
隨意留個言吧:)~