开发者

Page Control Question

I am trying to figure out how to add a page control to my view correctly. I have a keypad currently on the view along with a picker, but I want to separate the keypad and picker.

So I want to swipe to page two, and load a different view which essentially just has a picker. Page one will just have a keypad.

I can't find an example of a page control that switches to two separate views. I looked at the apple 开发者_如何学运维example PageControl, but that did not solve my issues.

Any help, suggestions are much appreciated.


You're not going to be able to do this with the native keypad - it doesn't belong to any one view, and so cannot be "paged" in the manner you describe.

As for a couple of hints as far as implementing paging: what you'll want to do is make a UIScrollView, set it's contentSize to be two pages wide (or more if you prefer), and set pagingEnabled to YES. Then add your pages as subviews. Note that the UIPageControl does not itself implement paging - it is an indicator only.

Some basic sample code (untested) assuming horizontal paging:

- (void) initPagesForScrollview:(UIScrollView*) scrollView
{
    CGRect pageFrame = CGRectMake(0, 0, scrollView.bounds.size.width,
        scrollView.bounds.size.height);

    scrollView.contentSize = CGSizeMake(pageFrame.size.width * 2,
        pageFrame.size.height)
    scrollView.pagingEnabled = YES;

    UIView* page1 = ...
    page1.frame = pageFrame;
    [scrollView addSubview:page1];

    UIView* page2 = ...
    pageFrame.origin.x += pageFrame.size.width;
    page2.frame = pageFrame;
    [scrollView addSubview:page2];
}

Note the origin of page 2 shifted to the right to make it begin off screen.

You can also do most of this through interface builder, but that's a little more difficult to demonstrate here... Feel free to ask if there's something specific you need.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜