0

を作成し、xib次のコードでビュー内に表示しました。

    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、次のコードから示しました。

このビューを削除するにはどうすればよいですか。が呼び出されている がありUIButtonます。IBAction

ありがとう

4

2 に答える 2

9

ビュー (プロパティまたはインスタンス変数) への弱い参照を保持し、次のremoveFromSuperviewように呼び出します。

[self.viewToRemove removeFromSuperview];
于 2014-05-02T12:52:32.230 に答える