Animation/Segue 从 ViewController 到具有不同数据的自身 - Swift

Animation/Segue from ViewController to itself with different data - Swift

我确实有 DetailViewController,其中包含数组中单个对象的信息。 (例如,我有一系列汽车,我想在 detailViewController 上显示阵列中的一辆汽车)

通过滑动left/right,我想查看数组中的next/previous辆汽车。

到目前为止,我只是更改了与当前汽车对象匹配的标签文本,但我希望每次滑动时都有动画。

switch swipeGesture.direction {
        case UISwipeGestureRecognizerDirection.Left:
            if currentIndex < events.count-1 {
                currentIndex += 1
            }
        case UISwipeGestureRecognizerDirection.Right:
            if currentIndex != 0 {
                currentIndex -= 1
            }
        default:
            break
        }

那么,实现这一目标的最有效方法是什么?

你必须使用 UIPageViewController