gpt4 book ai didi

iOS swift : UIPanGestureRecognizer on 2 differents views

转载 作者:行者123 更新时间:2023-11-28 07:01:47 27 4
gpt4 key购买 nike

我是 swift/xcode 的新手,我对 UIPanGestureRecognizer 有疑问。我正在尝试做一个滑动菜单,当你“平移”他时它会滑动。滑动菜单运行良好,我可以通过平移菜单 (UIViews) 来滑动它。但是这个菜单必须在开始时隐藏。所以我在它下面放了一个小箭头。这是问题所在...我想要一个 UIpanGestureRecognizer 执行与前一个相同的操作。当然,当我平移箭头时。所以,这是有效的代码:

// all is working with this code. handlePan is working well.
var panGestureRecognizer:UIPanGestureRecognizer!
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "handlePan:")
self.addGestureRecognizer(panGestureRecognizer)

这就是我对箭头的尝试:

let mysubView = UIView()
let arrowView = UIImageView()
let imageName = "arrow"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)

var panGestureRecognizerArrow:UIPanGestureRecognizer!


//put subview bellow the menu
mysubView.frame = CGRect(x: self.bounds.size.width / 2 - 15, y: self.bounds.height, width: 30, height: 30)
//put arrow bellow the menu
imageView.frame = CGRect(x: self.bounds.size.width / 2 - 5, y: self.bounds.height, width: 10, height: 10)

addSubview(imageView)
//put a invisible subview over image, to have a bigger "hit box"
addSubview(mysubView)

//I think the problem is HERE
panGestureRecognizerArrow = UIPanGestureRecognizer(target: mysubView, action: "handlePan:")
self.addGestureRecognizer(panGestureRecognizerArrow)
//it did'nt passed by the handlePan function when I pan mysubView. There is debug console out in it.

如评论所述,我认为问题出在最后两行。有人知道出了什么问题吗?

最佳答案

您应该将 UIPanGestureRecognizer 附加到 mysubView:

panGestureRecognizerArrow = UIPanGestureRecognizer(target: self, action: "handlePan:")
mysubView.addGestureRecognizer(panGestureRecognizerArrow)

对于在屏幕边缘附近开始的平移手势,您可以使用 UIScreenEdgePanGestureRecognizer

关于iOS swift : UIPanGestureRecognizer on 2 differents views,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31850770/

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