显示模态后移动视图 - 可能与 AutoLayout 相关 [英] Shifting view after displaying modal - possibly AutoLayout related

查看:20
本文介绍了显示模态后移动视图 - 可能与 AutoLayout 相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我展示了一个带有几个标签和一个按钮的简单视图,都在一个 UIScrollView 中,并使用自动布局进行布局.

I present a simple view with a couple of labels and a button, all inside a UIScrollView and laid out using auto layout.

该按钮呈现另一个视图,其中包括一个用于关闭的导航项.

The button presents another view, which includes a navigation item for dismissal.

然而,在解雇后,原始UIScrollView的内容被偏移了.奇怪的是,它的偏移量似乎与呈现时的滚动位置有关.

After dismissal, though, the content of the original UIScrollView is offset. Strangely, the amount by which it is offset seems related to the scroll position at the time of presentation.

演示项目这里是这个问题的一个小例子.在 iPhone 模拟器中运行它并滚动到底部以使用模态"按钮.在关闭模式尝试滚动回顶部后 - 问题应该很清楚.

The demo project here is a small example of this issue. Run it in the iPhone simulator and scroll to the bottom to use the 'modal' button. After dismissing the modal attempt to scroll back to the top - the issue should be clear.

或者参考下图中的滚动条来查看问题.

Or refer to the scroll bar in the images below to see the problem.

演示前

演示后

推荐答案

我不是 AutoLayout 的专家,但我通过添加标签 & 修复了它按钮约束到 self.view 而不是 self.scrollView.

I'm not an expert in AutoLayout, but I fixed it by adding the label & button constraints to self.view instead of self.scrollView.

例如:

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[l1]"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:@{@"l1":self.l1}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[l1]"
                                                                  options:0
                                                                  metrics:nil
                                                                    views:@{@"l1":self.l1}]];

为什么这会修复它......不知道:D

Why this fixes it... have no idea :D

这篇关于显示模态后移动视图 - 可能与 AutoLayout 相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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