gpt4 book ai didi

iOS : Resizing subview by removing a subview

转载 作者:行者123 更新时间:2023-11-29 12:41:54 27 4
gpt4 key购买 nike

  • 我有一个包含 3 个 subview 的 View ,分别称为 view Aview Bview C
  • 当我删除 subview 时,意味着我需要自动设置边距以进行调整。
  • 当我删除 view A 意味着,剩余的 views 必须自动向上移动。

注意:不在autolayout中。请告诉它如何在 automask

中实现

enter image description here

最佳答案

它不会自动工作,你需要编程一下,你可以试试下面的代码来实现,

//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;
}];

}
}

希望对你有帮助。

干杯。

关于iOS : Resizing subview by removing a subview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24670530/

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