我目前正在开发一个iOS应用程序使用迅速。我使用重写来编写自己的tocuhesBegan和tochesEnded函数。现在当我使用self.button时。
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
for touch in touches {
var tap = touch as? UITouch
var touchPoint: CGPoint = tap!.locationInView(self)
self.touchDown(touchPoint)
}
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
self.releaseTouch()
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesMoved(touches, withEvent: event)
}
func touchDown(point: CGPoint){
if rippleEffect == true {
touchView.frame = touchViewInitFrame
self.addSubview(touchView)
var touchViewFrameXPosition: CGFloat = point.x - (frame.size.width) / 2
println("X position = \(touchViewFrameXPosition)")
var touchViewFrameYPosition: CGFloat = -(self.frame.size.width - self.frame.size.height) / 2
touchViewFrame = CGRectMake(touchViewFrameXPosition, touchViewFrameYPosition, frame.size.width, frame.size.width)
UIView.animateWithDuration(0.25, delay: 0.0, options: .CurveEaseInOut, animations: {
self.touchView.frame = self.touchViewFrame
}, completion: nil)
}
}
func releaseTouch(){
if rippleEffect == true {
UIView.animateWithDuration(0.0, delay: 0.0, options: .CurveEaseInOut, animations: {
self.touchView.removeFromSuperview()
}, completion: nil)
}
}它不会转到我在选择器中指定的函数。有没有其他人有这个问题,或者有人知道发生了什么事?
这是我在遇到问题时使用的代码。它是UIButton的一个子类。
发布于 2015-05-27 23:42:58
如果您重写了任何一个触摸方法,那么您应该覆盖所有四个方法并调用超级方法。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
//your code
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesEnded:touches withEvent:event];
//your code
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesMoved:touches withEvent:event];
//your code
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesCancelled:touches withEvent:event];
//your code
}发布于 2015-05-28 00:19:23
您的视图和按钮可能有两个不同的句柄,以证明尝试触摸屏幕上的其他任何位置,您的触摸就会被检测到,然而,在按下该按钮时,触摸是句柄,永远不会传递给其他处理程序。在执行所需操作之前/之后,您必须选择、拦截所有消息并处理它是否应该传递给原始句柄,或者实现按钮处理程序并将消息传递到链中:
覆盖命中测试确保superview接收所有的触摸,因为通过将自己设置为命中测试视图,superview拦截并接收通常首先传递给子视图的触摸。如果superview不覆盖hitTest:withEvent:,则触摸事件与它们第一次发生的子视图相关联,并且从未发送到superview。
https://stackoverflow.com/questions/30494888
复制相似问题