簡體   English   中英

iOS Swift:2種視圖上的UIPanGestureRecognizer

[英]IOS Swift : UIPanGestureRecognizer on 2 differents views

我是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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM