rd42
rd42

Reputation: 3594

iPhone UIScrollview Pages

I have a horizontal scrollview with :

[journal setPagingEnabled:YES];

I've been using a custom method to scroll to the right on the touch of a button

[journal setContentOffset:CGPointMake(320,0) animated:YES];

Is there an already existing method for working with pages and how do I find it?

Thanks, Rd

Upvotes: 2

Views: 2215

Answers (3)

Matt Wilding
Matt Wilding

Reputation: 20163

If you're looking for something like [myScrollView scrollToPage:3], then no, there is no built in method. It's also pretty easy to roll your own if you really want something explicit. Assuming a horizontally paged UIScrollView:

- (void)scrollUIScrollView:(UIScrollView*)scrollView toPage:(NSInteger)page {

    CGFloat pageWidth = scrollView.frame.size.width;
    CGFloat pageHeight = scrollView.frame.size.height;
    CGRect scrollTarget = CGRectMake(page * pageWidth, 0, pageWidth, pageHeight);
    [scrollView scrollRectToVisible:scrollTarget animated:YES];
}

Okay, the method name is terrible, but that's the basic idea. I may be nicer in a Category on UIScrollView.

Upvotes: 3

Bartosz Ciechanowski
Bartosz Ciechanowski

Reputation: 10333

Here's a brilliant blog post on paged UIScrollView by Matt Gallagher. I used it in a project of mine, required some tweaking but otherwise was working as expected.

Upvotes: 1

Joe
Joe

Reputation: 57179

The UIPageControl works similar to the way that the iPhone's SpringBoard (home screen) functions.

Upvotes: 0

Related Questions