UIPageControl select 点并转到该页面

UIPageControl select dot and go to that page

我有一个UIViewController,里面有一个UIView,我在其中添加了一个UIPageViewControllerUIViewController作为代表。问题是 UIPageViewControllerUIPageControl 没有像我预期的那样对点 selection 起作用。

我原以为如果我 select 点 4,它会带我到点 4,但是,它不是那样工作的。如果我 select UIPageControl 的右半部分(图像的蓝色方块内),它总是转到下一页,如果我 select 左半部分,它总是转到上一页UIPageControl 的(在图像的红色方块内)。所以,如果我在第 2 页并且 select 在第二个点附近,它会转到第 1 页(而不是停留在第 2 页)

此外,如果我恰好在其中一个点(任何点)内单击,则单击将被忽略,尽管我不确定这在设备上是如何工作的(因为在设备中更难准确地在一个点内单击点).

我的问题:

1 - 完全忽略点内的行为是否正常(恰好在点内,我的意思是不在点周围)?

2 - selectUIPageController 的两半在页面之间移动是否正常?

3 - 我怎样才能做到,如果我按下点 X,它会带我到第 X 页(而不是当前的两半行为)?

注:我更喜欢swift

我建议你使用外部库,因为这个问题或多或少已经解决了。通过子类化本机页面控件来实现非常复杂,但您可能可以在某处找到实现。

这个库完全可以满足您的需求(跳转到页面):

https://github.com/Spaceman-Labs/SMPageControl

在文档中,查找 "Direct Page Selection"

部分

希望对您有所帮助!

编辑:还有几个库需要研究:

https://github.com/TanguyAladenise/TAPageControl https://github.com/nicklockwood/FXPageControl(非常广泛,可能太多了)

1 - Is ignoring exactly inside the dots behavior normal (by exactly inside the dots, I mean not around them)?

我从来没有遇到过这种情况。我会说这不正常。某些东西可能会覆盖它。

2 - Is two halves selection of the UIPageController to move between pages behavior normal?

是的,这是 UIPageController 的默认行为。

3 - How can I make it so that if I press the dot X, it takes me to page X (instead of the current two halves behavior)?

我建议不要这样做。默认情况下不是这种方式的原因是触摸 space 太小(当使用手指而不是鼠标时)。所以只前进和后退是有意义的。如果出于某种原因确实需要,您必须创建自定义 UIControl 才能执行此操作。