ios - 如何从 superView 中删除 View?

标签 ios objective-c storyboard xib superview

我制作了一个 xib 并通过以下代码在 View 中显示它。

    NSArray *xibContents = 
        [[NSBundle mainBundle] loadNibNamed:@"PickupAddressView"
            owner:self 
            options:nil];

    UIView *view = [xibContents objectAtIndex:0]; // Safer than objectAtIndex:0
    //UIView *subView=[view.subviews objectAtIndex:0];

    [view setFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
    CGRect tempFrame=view.frame;
    tempFrame.size.width=300;//change acco. how much you want to expand
    tempFrame.size.height=350;
    [UIView beginAnimations:@"" context:nil];
    [UIView setAnimationDuration:0.2];
    view.frame=tempFrame;
    //[UIView commitAnimations];
    [view setFrame:CGRectMake(10.0f, 90.0f, 300.0f, 350.0f)];
    [view setBackgroundColor:
      [UIColor colorWithPatternImage:
        [UIImage imageNamed:@"Register_bg"]]];
    [UIView commitAnimations];

    [view removeFromSuperview];
    [self.view addSubview:view];

我正在使用 UIStoryboard,并制作了这个 xib 并通过以下代码显示。

如何删除此 View 。我有一个 UIButton,正在调用其 IBAction

谢谢

最佳答案

保留对 View 的弱引用(属性或实例变量)并像这样调用 removeFromSuperview:

[self.viewToRemove removeFromSuperview];

关于ios - 如何从 superView 中删除 View?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23428616/

相关文章:

macos - Xcode 9 Storyboard 窗口位置自动保存

ios - 忽略 #pragma 发出的警告

ios - 如何使 UIButton 文本动态化?

ios - 在 iOS 上处理大量像素

iphone - Objective-C:如何为iPhone和iPad定义CELL_CONTENT_WIDTH?

objective-c - UIPopoverController的奇怪错误

iphone - 如何在 iPhone SDK 中将 SQLite 文件导出为 CSV 文件

ios - VS 连接 Mac 时,Visual Studio 2017 v15.9 Storyboard 设计器无法连接 Mac

ios - 导航栏清除颜色为黑色

iphone - 模拟推送的 NavigationController 的更新 View