Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). 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.

However, when the view loads, the horizontal scroll view is about 100 pixels higher than where it should be. 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:

-(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.

like image 703
Lawrence Wu Avatar asked Oct 07 '22 11:10

Lawrence Wu


1 Answers

Jumping in UIScrollView usually happens when you have set pagingEnabled = YES and the contentOffset is set to a position which is not on a page boundry (dividable by bounds.size.height).

like image 91
LK__ Avatar answered Oct 12 '22 23:10

LK__