Im пытается создать UIPanGestureRecognizer к определенному UIViewSwift: Set UIPanGestureRecognizer в UIView
self.halfViewBlue.frame = CGRectMake(0, 0, self.bounds.width/2, self.bounds.height)
self.halfViewBlue.backgroundColor = UIColor.blueColor()
halfViewBlue.alpha = 1.0
self.addSubview(self.halfViewBlue)
self.halfViewRed.frame = CGRectMake(self.frame.midX, 0, self.bounds.width/2, self.bounds.height)
self.halfViewRed.backgroundColor = UIColor.redColor()
halfViewRed.alpha = 1.0
self.addSubview(self.halfViewRed)
//Pan Gesture for Red
let panGestureRed = UIPanGestureRecognizer()
panGestureRed.addTarget(self, action: "handlePanRed:")
self.addGestureRecognizer(panGestureRed)
self.userInteractionEnabled = true
//Pan Gesture for Blue
let panGestureBlue = UIPanGestureRecognizer()
panGestureBlue.addTarget(self, action: "handlePanBlue:")
self.addGestureRecognizer(panGestureBlue)
self.userInteractionEnabled = true
}
func handlePanRed(gesture : UIPanGestureRecognizer){
if (gesture.state == UIGestureRecognizerState.Changed || gesture.state == UIGestureRecognizerState.Ended){
let velocity : CGPoint = gesture.velocityInView(halfViewRed)
//Pan Down
if(velocity.y > 0){
print("Panning down")
hideRedBar()
produceBlueBar()
}
//Pan Up
if(velocity.y < 0){
print("panning up")
hideBlueBar()
produceRedBar()
}
}
}
func handlePanBlue(gesture : UIPanGestureRecognizer){
if (gesture.state == UIGestureRecognizerState.Changed || gesture.state == UIGestureRecognizerState.Ended){
let velocity : CGPoint = gesture.velocityInView(halfViewBlue)
//Pan Down
if(velocity.y > 0){
print("Panning down")
hideBlueBar()
produceRedBar()
}
if(velocity.y < 0){
print("panning up")
hideRedBar()
produceBlueBar()
}
}
}
Здесь я просто создать два UIViews, как разделение вертикально по экрану (одинаково). Затем я добавляю два объекта panGestures и функцию, чтобы следовать за ним. Моя проблема заключается в том, что единственным признаком panGesture, который распознается, является «panGestureBlue», и странно я могу управлять им на любой части экрана, а не только в половине, где находится «halfViewBlue». Итак, я предполагаю, что оба panGestures добавляются в self.view, а не в UIView, который, предположительно, должен быть помещен, и «panGestureBlue» читается, потому что он добавляется после «panGestureRed». Вместо «self» в «panGestureBlue.addTarget» я попытался поместить «halfViewBlue», но он разбился.
Как я могу исправить эту проблему !?
AHHH настолько глупыми. Спасибо, мой добрый сэр! –