簡體   English   中英

iOS UIPageControl左右點擊時更改行為

[英]iOS UIPageControl change behavior when tap left and right

我正在使用默認的UIPageControl UIPageViewController是通過編程創建的。 dataSourcedelegate方法也已正確配置。

我正在嘗試實現與iOS主頁中相同的行為。

右擊應轉到下一頁。 輕按一下即可轉到上一頁。

這些行為是默認行為。 一切正常, 除了在最后一頁上輕按時,它會轉到第一頁。 即無限循環。 相同的首頁和左鍵,它需要到最后一頁。

我已經阻止了viewControllerBeforeviewControllerAfter方法中的無限循環以進行滑動手勢。

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController?

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController?

發現:

  • 點擊右側的最后一頁時,調用viewControllerBefore
  • 點擊左側的第一頁時,調用viewControllerAfter

反正有處理這種情況嗎? 我在iOS主屏幕中看到了預期的行為。

當頁面的索引為0n - 1時,只需以上述方法返回nil 其中n是總頁數。

例:

func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {

    // Check if index is zero, then return nil   
}

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
        // Check if index is equal to total page count, then return nil   
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM