I'm very new in swift/xcode and i have a problem with UIPanGestureRecognizer. I'm trying to do a sliding menu who slide when you "pan" him. The sliding menu is working well, and i can slide it by panning the menu (UIViews). But this menu have to be hidden at the beginning. So I put a little arrow bellow it. Here is the problem... I want had a UIpanGestureRecognizer who did the same action of the previous one. When i'm panning the arrow, of course. So, here is the code who works :
// all is working with this code. handlePan is working well.
var panGestureRecognizer:UIPanGestureRecognizer!
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "handlePan:")
self.addGestureRecognizer(panGestureRecognizer)
And this is what i have try for the arrow:
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.
Like said commentary, i think the problem is in the last two line. Someone know what's wrong ?
You should attach UIPanGestureRecognizer
to the mysubView
:
panGestureRecognizerArrow = UIPanGestureRecognizer(target: self, action: "handlePan:")
mysubView.addGestureRecognizer(panGestureRecognizerArrow)
For panning gestures that start near an edge of the screen you can use UIScreenEdgePanGestureRecognizer as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.