不仅在滚动视图结束减速时,如何更改uipagecontrol点?

发布于 2025-01-24 09:54:50 字数 834 浏览 0 评论 0原文

我已经创建了一个用户入职,用2个项目创建了收集视图

集合视图具有uipagecontrol,该显示了当前有效的页面用户。

问题是,在用户刷新到下一个\上一个屏幕之后,我才能更改活动UIPAGECONTROL的状态 DOT。

这就是现在的样子: gif

我想要这种行为,所以当您开始刷卡uipagecontrol 应该已经将其活动点更改为下一个\上一个,而我一定要结束滑动(抬起手指)。

您可以在GIF上检查我想要的内容: gif

这就是我更改uipagecontrol 点现在:

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    let width = scrollView.frame.width
    currentPage = Int(scrollView.contentOffset.x / width)
    pageControl.currentPage = currentPage
}

应该如何修改我的代码,用于实现行为的方法?我在Stackoverflow上找不到任何类似的问题。

I have created a User Onboarding as a Collection View with 2 items.

The Collection View has a UIPageControl which shows an active page user currently on.

The problem is I can change the state of active UIPageControl dot only when the transition is ended, after user swiped to the next\previous screen.

This is how it looks now: GIF

I want the behaviour so when you start to swipe UIPageControl should already change its active dot onto the next\previous one without me necessarily ending the swipe (lift the finger).

You can check what I want on the gif: GIF

Here is how I change the UIPageControl dot now:

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    let width = scrollView.frame.width
    currentPage = Int(scrollView.contentOffset.x / width)
    pageControl.currentPage = currentPage
}

How my code should be modified, which method to use to achieve the behaviour? I couldn't find any similar questions on StackOverflow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唯憾梦倾城 2025-01-31 09:54:50

基于您的问题...

  • 您只有两个单元格(页面)
  • ,您希望页面控件反映出哪个页面是 最可见的,

而不是scrollviewdidendendendDecelerating,实现:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let fw = scrollView.frame.width
    // get the percentage scrolled
    let pct = scrollView.contentOffset.x / fw
    // if it's less-than 50%, we're at page 0
    // else, we're at page 1
    pageControl.currentPage = pct < 0.5 ? 0 : 1
}

Based on your question...

  • you have only TWO cells (pages)
  • you want the page control to reflect which page is most visible

Instead of scrollViewDidEndDecelerating, implement:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let fw = scrollView.frame.width
    // get the percentage scrolled
    let pct = scrollView.contentOffset.x / fw
    // if it's less-than 50%, we're at page 0
    // else, we're at page 1
    pageControl.currentPage = pct < 0.5 ? 0 : 1
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文