如何触发Swift点击手势识别器?

我在这里查看了有关姿势识别器不起作用的类似文章,并且尝试了所有解决方案,但均无济于事。过去,我已经创建了数十个手势识别器,并且花了几个小时才使它无法工作,并且我准备淹死自己。

以下是我在视图中拥有的3个水平堆栈: https://imgur.com/a/HKIaNRV

我已经在水平堆栈中添加了手势识别器,如下所示:

menuView.addSubview(Hstack1)
Hstack1.anchor(top: nil,left: menuView.leftAnchor,bottom: nil,right: menuView.rightAnchor,paddingTop: 0,paddingLeft: 15,paddingBottom: 0,paddingRight: 15,width: menuView.frame.width,height: 30)
Hstack1.topAnchor.constraint(equalTo: menuView.topAnchor,constant: 100).isactive = true
var tap = UITapGestureRecognizer(target: self,action: #selector(openProfileController))
Hstack1.addGestureRecognizer(tap)

应该触发的功能:

@objc func openProfileController() {
    navigationController?.pushViewController(ProfileController(),animated: true)
}

我什至尝试使用操作方法将“个人资料”设置为按钮,但这没有用。我还尝试向整个黑色菜单视图添加手势,但未触发任何操作。

编辑: 我已经在视图中玩了好几个小时,并且了解到它与菜单视图框架有关。为了获得幻灯片菜单,我将动画中的视图控制器移动如下:

self.view.frame.origin.x = self.view.frame.origin.x + 250

菜单的框架最初是:

menuView.frame = CGRect(x: -250,y: 0,width: 250,height: view.frame.height)

但是由于它是视图控制器的子视图,因此它也向右移动250。在视觉上,这正是我想要的。但是,在此动画过程中,menuView的框架似乎没有更新,并且继续保持在-250,0。

关于如何解决此问题的任何想法?

coolio0303 回答:如何触发Swift点击手势识别器?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2488675.html

大家都在问