gpt4 book ai didi

ios - 点击手势未触发

转载 作者:行者123 更新时间:2023-11-28 08:34:43 28 4
gpt4 key购买 nike

我正在将 FrontViewController 的 View 加载到我当前的 View Controller MyVideosViewController 中。

我已将 2 个通知观察器添加到我的 MyVideosViewController viewdidload()

    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyVideosViewController.playLatestvideoClick), name: latestKey, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyVideosViewController.playMostWatchedvideoClick), name: mostKey, object: nil)

在我的FrontViewController

 //MARK: -Gesture Play
func playLatestvideoClick(sender: UITapGestureRecognizer)
{
print("----- PLAY GESTURE TAPPED ------")
let imgVw = sender.view as! UIImageView
api.selectedVideoID = String(imgVw.tag)
let homeviewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("MYVIDEO") as? MyVideosViewController

NSNotificationCenter.defaultCenter().postNotificationName(self.latestKey, object: nil)
}

func playMostWatchedvideoClick(sender: UITapGestureRecognizer)
{
print("----- PLAY GESTURE TAPPED ------")
let imgVw = sender.view as! UIImageView
api.selectedVideoID = String(imgVw.tag)
let homeviewcontroller = self.storyboard?.instantiateViewControllerWithIdentifier("MYVIDEO") as? MyVideosViewController

NSNotificationCenter.defaultCenter().postNotificationName(self.mostKey, object: nil)
}

这就是我在 FrontViewController 中设置手势操作的方式

let tapPlay = UITapGestureRecognizer.init(target: self, action: (#selector(FrontViewController.playLatestvideoClick(_:))))
self.imgVideo.addGestureRecognizer(tapPlay)
self.imgVideo.userInteractionEnabled=true

但是当我点击手势时,这些方法中的任何一个都没有触发。这是什么原因?请帮助我。

更新

是这样的。如果我重新加载这个 MyVideoViewController 它第一次工作。然后它不起作用

最佳答案

请尝试如下代码:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyVideosViewController.playLatestvideoClick(_:)), name: latestKey, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyVideosViewController.playMostWatchedvideoClick(_:)), name: mostKey, object: nil)

你需要像这样传递 sender (_:) 然后它会调用这个方法。

希望对你有帮助。

关于ios - 点击手势未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38119716/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com