Lawrence Wu
Lawrence Wu

Reputation: 212

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.

Upvotes: 5

Views: 1805

Answers (3)

LK__
LK__

Reputation: 6713

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

Upvotes: 4

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

Move this line

horizontalScrollView.frame = CGRectMake(0, 540, 320, 460);

In viewWillAppear instead of viewDidLoad, see if it works

Upvotes: 0

Jomnipotent17
Jomnipotent17

Reputation: 461

Just a quick thought because I am currently messing with UIScrollView too. You could try using -(void)viewWillAppear:(BOOL)animated. E.g. 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.

Upvotes: 0

Related Questions