开发者

How to programmatically set the current page for UIPageControl?

I have 3 "pages" (page 0, page 1, page 2) in a UIScrollView that are snapped to by finger swipes. There is a UIPageCont开发者_开发技巧rol there too. The UIScrollView starts off presenting page 0. What I want to do is present page 3 FIRST sometimes. How can I do this programmatically.

Simply setting currentPage (of UIPageControl) to the page number does nothing by the way.


(From the PageControl example)

To go directly to a particular section of the scrollView use

CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];

I just implemented the same, e.g scrollview and page control and used the

pageControl.currentPage = {pageNumber};

which worked perfectly, are you sure that the pageControl outlet is set correctly in Interface Builder (if you're using it).

If the problem is that the scrollView is not working, and not the pageControl. Then make sure that you have the contentsize of the scrollView set correctly.

    scrollView.contentSize = CGSizeMake(320*numberOfPages, scrollView.frame.size.height);

To this scrollview you then add the content to each section

page1ViewController.view.frame = CGRectMake(0, 0, 320, 200);
[scrollView addSubview:page1ViewController.view];

Next page gets pushed over 1 screen width

page2ViewController.view.frame = CGRectMake(320, 0, 320, 200);
[scrollView addSubview:page2ViewController.view];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜