简体   繁体   中英

Horizontal paging in my app

I want to make horizontal paging in my app. I have big text, which placed in UITextView, but I want to make horizontal paging, like iBooks or bookmate. Do you have any solution or idea?

Have a look at the new (iOS 5) class UIPageViewController . For the iBooks page curl effect, try using

[controller initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl 
              navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal 
                            options:nil];

You can then set the view controllers using setViewControllers:direction:animated:completion: . For more reference for this class, visit the UIPageViewController Class Reference .

Use this handy class called PagedView which manages a paging scroll view as well as view loading/unloading and reuse for you.

You have to implement two delegate methods to get it working:

- (NSUInteger)numberOfPagesInPagedView:(PagedView *)view;
- (UIView *)pagedView:(PagedView *)view viewForPageAtIndex:(NSUInteger)page;

They will look familiar if you've ever used UITableView . In numberOfPagesInPagedView: you just have to return the number of pages you want to display.

- (NSUInteger)numberOfPagesInPagedView:(PagedView *)view
{
    // return the number of pages in the paging view
    return 10;
}

In pagedView:viewForPageAtIndex: you have to return a view for a specific page index. You can reuse the views by sending the dequeueReusableViewWithIdentifier: message to the paged view.

- (UIView *)pagedView:(PagedView *)pagedView viewForPageAtIndex:(NSUInteger)page
{
    static NSString *reuseIdentifier = @"PageIdentifier";
    UIView *view = [pagedView dequeueReusableViewWithIdentifier:reuseIdentifier];
    if(view == nil) {
        view = [[[MyPageView alloc] initWithFrame:view.bounds] autorelease];
    }

    // add contents specific to this page index to the view

    return view;
}

In order to get view reuse working, your UIView subclass ( MyPageView ) should conform to the ReusableObject protocol and implement reuseIdentifier (in this case you would return @"PageIdentifier" ).

I have used this class in a number of projects and it works pretty well.

打开pageEnabled的UIScrollView?

You can use a UIWebView (subclass of UIScrollView) for your horizontal paging needs.

For it to work, you'd need to split the NSString that you use to store your text, depending on the size (and height) of your web view.

Store the split NSString into an NSArray, and then depending on user swipe, load up the correct 'page' (array index) and display with animation.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM