繁体   English   中英

iOS:通过删除子视图来调整子视图的大小

[英]iOS : Resizing subview by removing a subview

  • 我有一个视图,其中包含3 subivews view Asubivews称为view Aview Bview C
  • 删除子视图时,我需要自动设置边距以进行调整。
  • 当我删除view A ,其余views必须自动上移。

注意:不在autolayout 请告诉我如何在automask

在此处输入图片说明

它不会自动运行,您需要进行一些编程,可以尝试以下代码来实现此目的,

//Adding Delete Tap Gesture
-(void)addGestureToSubViews{
    for(UIView *view in parent.subviews){
        UITapGestureRecognizer *gesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteAction:)];
        [view addGestureRecognizer:gesture];
    }
}


-(IBAction)deleteAction:(UITapGestureRecognizer *)sender{
    UIView *view=sender.view;

    [UIView animateWithDuration:.3 animations:^{
        CGRect rect=view.frame;
        rect.origin.x=view.superview.frame.size.width;
        view.frame=rect;
    } completion:^(BOOL finished) {
        [self reArrangeSuperView:view.superview withDeletedViewFrame:view.frame];
        [view removeFromSuperview];

    }];

}

-(void)reArrangeSuperView:(UIView *)superView withDeletedViewFrame:(CGRect)frame{

    for(UIView *view in superView.subviews){
        CGRect rect=view.frame;

        if(rect.origin.y>frame.origin.y){
            rect.origin.y=frame.origin.y;
        }

        [UIView animateWithDuration:.3 animations:^{
            view.frame=rect;
        }];

    }
}

希望对您有所帮助。

干杯。

为此,您必须在属性检查器中隐藏视图,并且要向上推哪个视图,应设置视图的-contentoffset属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM