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

问题描述 投票:-1回答:1

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

我的第一页是:FeedViewController

第二详细页是:CommentsViewController

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

ios swift uitableview uiviewcontroller swipe
1个回答
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.
}
© www.soinside.com 2019 - 2024. All rights reserved.