gpt4 book ai didi

iphone - removeFromSuperview 移除所有 subview

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:51:23 28 4
gpt4 key购买 nike

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"will rotation");

for (UIButton *button in self.view.subviews) {
[button removeFromSuperview];
}

}

我对这段代码有疑问。我只需要从我的 View 中删除 UIButtons。但是这段代码也删除了我的 self.view 的所有 subview 。我该如何解决这个问题?

最佳答案

这样做:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"will rotation");

for (id subview in self.view.subviews) {
if([subview isKindOfClass:[UIButton class]]) //remove only buttons
{
[subview removeFromSuperview];
}
}

}

关于iphone - removeFromSuperview 移除所有 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12039635/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com