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

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

}

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

最佳答案

做这个:

- (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/

10-09 16:29