向左/向右滑动屏幕以浏览下一个/上一个视频

时间:2019-12-10 08:08:47

标签: ios swift uitableview uiviewcontroller swipe

我希望实现向左/向右滑动屏幕以导航下一个/上一个视频。我已经在使用tableView加载并在每个视频下方显示所有视频和评论/赞。 如果单击“评论”按钮,则下一页为详细页面,详细页面显示所有相关评论。 我想实现滑动屏幕来导航详细评论页面上的下一个/上一个视频。我是新手,却不知道该如何实施?

我的第一页是:FeedViewController

第二个detailPage是:CommentsViewController

Github链接:https://github.com/MasamMahmood/VideoApp

1 个答案:

答案 0 :(得分:0)

您正在将单个帖子传递到CommentsViewController。为了满足您的要求,您需要将整个帖子数组和支持索引传递给CommentsViewController。向左滑动会降低索引值,向右滑动会使索引增加1,也会重新加载所有视图。

代替使用:-

func commentPressed(post: IContentPost) {
    router.openComments(vc: self, post: post)
}

使用:-

func commentPressed(selectedPostIndex: Int, allPosts: [IContentPost]) {
    //set your CommentsViewController based on selected index
}

在CommentsViewController中:

@objc func handleSwipes(_ sender: UISwipeGestureRecognizer) {
    if (sender.direction == .left) {
       print("Swipe Left")
       selectedPostIndex -= 1   //add check for index less than 0
    }

    if (sender.direction == .right) {
       print("Swipe Right")
       selectedPostIndex += 1   //add check for index greater than post array count
    }

    //reload all your comments and selected post video.
}
相关问题