Reputation: 1095
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?
Upvotes: 0
Views: 1171
Reputation: 10265
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.
Upvotes: 1
Reputation: 2441
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.
Upvotes: 1
Reputation: 1107
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.
Upvotes: 0