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

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

问题描述

包含文本字段数组的 Stackview 嵌入在滚动视图中.我想更改某些操作的文本字段的顺序.删除和添加文本字段的方式会导致视图失真.我还通过从滚动视图中删除进行了测试.正常的 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天全站免登陆