用户登录
用户注册

分享至

在 UIScrollView 上更改页面

  • 作者: 阳光刺痛眼眸1990
  • 来源: 51数据库
  • 2022-10-20

问题描述

我有一个 10 页的 UIScrollView.我可以在它们之间轻弹.我还想要 2 个按钮(一个后退按钮和一个下一个按钮),当触摸它们时会转到上一页或下一页.我似乎无法想出办法来做到这一点.我的很多代码都来自 Apple 的页面控件示例代码.有人可以帮忙吗?

I have a UIScrollView with 10 pages. I am able to flick between them. I also want to have 2 buttons (a back button and a next button) which when touched will go to the previous or next page. I can't seem to figure out a way to do this though. A lot of my code comes from Apple's page control sample code. Can anybody help?

谢谢

推荐答案

你只需告诉按钮滚动到页面的位置:

You just tell the buttons to scroll to the page's location:

CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * pageNumberYouWantToGoTo;
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];
软件
前端设计
程序设计
Java相关