ios - 想要那个 .scroll 动画,即使没有在 UIPageViewController 中设置数据源

标签 ios swift uipageviewcontroller

我有一个 UIPageViewController,它显示五个 ViewControllers(包含在 ViewControllers 数组中)。我正在使用手势识别器向后/向前移动页面,而不是 viewControllerBefore/viewControllerAfter 方法。它工作正常,但页面突然改变。我想让动画类似于我以前使用 .scroll 应用时的动画。 我希望能够显示两个ViewControllers,类似于我们在.scroll动画中缓慢滑动时的体验。 你能建议怎么做吗? 谢谢。

正如我在这个问题中提到的那样,我遇到了滚动问题 -> [ Disable swiping in horizontal UICollectionView inside my PageViewController to swipe in UIPageViewController 所以,我决定评论这一行 -> self.dataSource = self 我决定明确提供与手势相关的功能。

@objc func handleSwipe(gesture: UISwipeGestureRecognizer) {
    print(gesture.direction)
    switch gesture.direction {
    case UISwipeGestureRecognizer.Direction.down:
        print("down swipe")
    case UISwipeGestureRecognizer.Direction.up:
        print("up swipe")
    case UISwipeGestureRecognizer.Direction.left:

        self.setViewControllers([ViewControllerArray[1]], direction: .forward, animated: false, completion: nil)

    case UISwipeGestureRecognizer.Direction.right:

        self.setViewControllers([ViewControllerArray[2]], direction: .forward, animated: false, completion: nil)

    default:
        print("other swipe")
    }
}

最佳答案

animated 参数更改为 true

@objc func handleSwipe(gesture: UISwipeGestureRecognizer) {
    print(gesture.direction)
    switch gesture.direction {
    case UISwipeGestureRecognizer.Direction.down:
        print("down swipe")
    case UISwipeGestureRecognizer.Direction.up:
        print("up swipe")
    case UISwipeGestureRecognizer.Direction.left:

        self.setViewControllers([ViewControllerArray[1]], direction: .forward, animated: true, completion: nil)

    case UISwipeGestureRecognizer.Direction.right:

        self.setViewControllers([ViewControllerArray[2]], direction: .forward, animated: true, completion: nil)

    default:
        print("other swipe")
    }
}

关于ios - 想要那个 .scroll 动画,即使没有在 UIPageViewController 中设置数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57767548/

相关文章:

IOS:具有多个节点的 NSMXLParser

ios - 带有日期选择器的文本字段在日期快速更改时崩溃

ios - Swift NSPhotoLibraryUsageDescription 键不读

ios - fatal error : unexpectedly found nil while unwrapping an Optional value - Swift with NSURLRequest

ios - PageViewController点击事件

iphone - ios中XMPPFramework的TURNSocket连接成功后如何接收文件?

ios - 弱委托(delegate)和类协议(protocol)

ios - 用户输入的值保存到核心数据(?)但未出现在 TableView 中

ios - 修复了 UIPageViewController 的背景滚动效果

ios - 如何使 UIPageViewController 背景半透明?