关闭 ModalViewController 后 UIScrollView 的内容发生了变化

时间:2022-11-03
本文介绍了关闭 ModalViewController 后 UIScrollView 的内容发生了变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个分页滚动视图.每个页面都有一个管理按钮网格的视图控制器(buttonViewController).如果按下其中一个按钮,buttonViewController 会模态地弹出另一个视图控制器(detailViewController).

I have a paged scrollview. Each page has a viewcontroller (buttonViewController) that manages a grid of buttons. If you press one of the buttons, the buttonViewController pops up another viewcontroller (detailViewController) modally.

问题是,当我关闭模态视图控制器时,可见的 buttonViewController 向下移动了大约 20 像素.奇怪的是只有可见页面被移动.如果我滚动到另一个已经加载的页面,它仍然在正确的位置.

The problem is, when I dismiss the modal view controller, the visible buttonViewController is shifted down by what looks like about 20 pixels. The weird thing is that only the visible page is shifted. If I scroll over to another page that is already loaded, it is still in the correct position.

我的问题与 关闭 modalViewController 移动主视图按钮基本相同iphone周围

但是,该问题的公认答案假定状态栏是隐藏的.我没有在我的应用程序中隐藏状态栏.

However, the accepted answer to that question assumed that the status bar is hidden. I am not hiding the status bar in my application.

还有其他想法吗?

还有一点需要注意:这种转变只会在我第一次启动模态视图控制器时发生.如果我继续打开和关闭模态视图控制器,一切都保持不变.

One more note: The shift only happens the first time I launch a modal view controller. If I keep opening and closing the modal view controller, everything stays the same.

进一步说明:如果我添加以下代码:

One further note: if I add the following code:

    CGRect frame = self.view.frame;
frame.origin.y=0;
self.view.frame = frame;

在我关闭模态视图控制器之后,我可以解决这个问题.框架似乎在 y 方向移动了 20 像素.不过,我仍然不知道是什么导致了这一举动.

after I dismiss the modal view controller, then I can work around the problem. The frame seems to move by 20pixels in y. I still don't know what's causing the move though.

推荐答案

原来这与:ModalViewController 在分页滚动视图滚动时不显示动画

我的一些视图控制器的高度不匹配,这让一切都崩溃了.

I had mismatched the heights of some of my viewcontrollers, and that was throwing everything off.

有些视图的高度为 460 像素,有些为 480 像素.出于某种原因,每当模态视图控制器消失时,它就会移动 20 像素.一旦我把所有东西都做成了 460 像素,一切都很好.

Some of the views had heights of 460pixels, some had 480pixels. For some reason, this made it shift by 20pixels evertime a modal view controller disappeared. Once I made everything 460pixels, everything worked great.

这篇关于关闭 ModalViewController 后 UIScrollView 的内容发生了变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一条:用于可缩放 UIScrollView 的矢量绘图 下一条:带有自动布局的 UIScrollView 内的动态 UILabel 高度

相关文章

最新文章