Stackview交换或更改视图顺序 [英] Stackview exchange or change order of views

查看:400
本文介绍了Stackview交换或更改视图顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

包含textfield数组的Stackview嵌入在scrollview中.我想在某些操作上更改文本字段的顺序.删除和添加文本字段的方法导致视图变形.我还通过从scrollview中删除进行了测试.普通stackview交换也不能正确显示.我正在使用索引来更改:

Stackview containing array of textfield is embedded in scrollview. I want to change the order of the text fields on some actions. The way to remove and add the textfield results in distorted view. I also tested by removing from scrollview. Normal stackview too the exchange does not appear properly. I am using indexes to change :

stackView.removeArrangedSubview(localityTF) stackView.insertArrangedSubview(localityTF, at: 2)

推荐答案

这是奇怪的行为,但是自动布局系统存在问题,应该在更新localityTF之前对其进行更新.同样不要忘记removeArrangedSubview不会从subviews数组中删除该视图:

It is strange behaviour, but problem with the autolayout system, that should be updated before you can add localityTF back. Also don't forget that removeArrangedSubview does not remove the view from subviews array:

[self.stackView removeArrangedSubview:_label1];
[self.stackView setNeedsLayout];
[self.stackView layoutIfNeeded];

[self.stackView insertArrangedSubview:_label1 atIndex:2];   
[self.stackView setNeedsLayout];

这篇关于Stackview交换或更改视图顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆