我的应用程序中的水平分页
我想在我的应用程序中进行水平分页。 我有大文本,放置在 UITextView 中,但我想进行水平分页,例如 iBooks 或 bookmate。 您有什么解决方案或想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看一下新的 (iOS 5) 类
UIPageViewController
。对于 iBooks 页面卷曲效果,请尝试使用您然后可以使用
setViewControllers:direction:animated:completion:
设置视图控制器。有关此类的更多参考,请访问 UIPageViewController 类参考。Have a look at the new (iOS 5) class
UIPageViewController
. For the iBooks page curl effect, try usingYou can then set the view controllers using
setViewControllers:direction:animated:completion:
. For more reference for this class, visit the UIPageViewController Class Reference.使用这个名为 PagedView 的方便类,它也可以管理分页滚动视图作为视图加载/卸载和重用。
您必须实现两个委托方法才能使其正常工作:
如果您曾经使用过
UITableView
,它们看起来会很熟悉。在numberOfPagesInPagedView:
中,您只需返回要显示的页面数。在
pagedView:viewForPageAtIndex:
中,您必须返回特定页面索引的视图。您可以通过向分页视图发送dequeueReusableViewWithIdentifier:
消息来重用视图。为了使视图重用正常工作,您的
UIView
子类 (MyPageView
) 应符合ReusableObject
协议并实现reuseIdentifier
> (在这种情况下,您将返回@"PageIdentifier"
)。我已经在许多项目中使用过这个类,并且效果很好。
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:
They will look familiar if you've ever used
UITableView
. InnumberOfPagesInPagedView:
you just have to return the number of pages you want to display.In
pagedView:viewForPageAtIndex:
you have to return a view for a specific page index. You can reuse the views by sending thedequeueReusableViewWithIdentifier:
message to the paged view.In order to get view reuse working, your
UIView
subclass (MyPageView
) should conform to theReusableObject
protocol and implementreuseIdentifier
(in this case you would return@"PageIdentifier"
).I have used this class in a number of projects and it works pretty well.
UIScrollView 是否打开了 pageEnabled?
UIScrollView with pageEnabled turned on?
您可以使用 UIWebView(UIScrollView 的子类)来满足水平分页需求。
为了使其工作,您需要根据 Web 视图的大小(和高度)拆分用于存储文本的 NSString。
将分割后的 NSString 存储到 NSArray 中,然后根据用户的滑动,加载正确的“页面”(数组索引)并以动画显示。
希望有帮助。
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.