[英]UIScrollView jumps down when first touched
I have two UIScrollViews, one horizontal, one vertical, both two pages each (as in, the horizontal one is two pages wide, and the vertical one is two pages high). 我有两个UIScrollViews,一个是水平的,一个是垂直的,每个都有两个页面(如图所示,水平一个是两页宽,垂直一个是两页高)。 The horizontal scrollview is in the vertical one.
水平滚动视图位于垂直滚动视图中。 I am trying to imitate Calcbot's design, where you can scroll left/right for buttons and up/down for history.
我试图模仿Calcbot的设计,你可以向左/向右滚动按钮,向上/向下滚动历史记录。
However, when the view loads, the horizontal scroll view is about 100 pixels higher than where it should be. 但是,当视图加载时,水平滚动视图比它应该的位置高约100个像素。 Then, when I touch it and begin moving it a little, it jumps/skips down to the correct position and stays there.
然后,当我触摸它并开始移动它时,它跳跃/跳到正确的位置并停留在那里。 How do I have it appear correctly right from the start?
如何从一开始就正确显示?
Here is my code for viewDidLoad: 这是我的viewDidLoad代码:
-(void)viewDidLoad {
horizontalScrollView.pagingEnabled = YES;
verticalScrollView.pagingEnabled = YES;
horizontalScrollView.contentSize = CGSizeMake(horizontalScrollView.bounds.size.width * 2, horizontalScrollView.bounds.size.height); // 2 pages wide.
verticalScrollView.contentSize = CGSizeMake(verticalScrollView.bounds.size.width, verticalScrollView.bounds.size.height * 2);
horizontalScrollView.delegate = self;
verticalScrollView.delegate = self;
[verticalScrollView addSubview:horizontalScrollView];
[verticalScrollView setContentOffset:CGPointMake(0, 640)];
[self.view addSubview:verticalScrollView];
horizontalScrollView.frame = CGRectMake(0, 540, 320, 460);
}
Thanks. 谢谢。
当你设置了pagingEnabled = YES并且contentOffset设置为不在页面边界上的位置(由bounds.size.height分割)时,通常会跳过UIScrollView。
Just a quick thought because I am currently messing with UIScrollView too. 只是一个快速思考,因为我目前正在搞乱UIScrollView。 You could try using
-(void)viewWillAppear:(BOOL)animated
. 您可以尝试使用
-(void)viewWillAppear:(BOOL)animated
。 Eg I set my min and max scrolling in that method because it depends on the size of the content which, from what I read, isn't set until viewWillAppear. 例如,我在该方法中设置了我的最小和最大滚动,因为它取决于内容的大小,从我读到的内容,直到viewWillAppear才设置。
Move this line 移动这一行
horizontalScrollView.frame = CGRectMake(0, 540, 320, 460);
In viewWillAppear
instead of viewDidLoad
, see if it works 在
viewWillAppear
而不是viewDidLoad
,查看它是否有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.