开发者

iPhone UIScrollview Pages

开发者 https://www.devze.com 2023-02-20 09:59 出处:网络
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

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


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号