我设法通过覆盖下面的功能并跟踪哪个按钮最后被触摸和倒数第二来创建合适的解决方案。触摸的最后一个按钮突出显示,倒数第二个按钮未突出显示。这是我进行两键测试的代码,以防有人发现它有用:
@IBOutlet weak var bottomButton: UIButton!@IBOutlet weak var topButton: UIButton!var lastTouchedButton: UIButton? = nilvar secondToLastTouchedButton: UIButton? = niloverride func touchesBegan(touches: Set<UITouch>?, withEvent event: UIEvent?) { let touch = touches?.first let location : CGPoint = (touch?.locationInView(self.view))! if topButton.pointInside(self.view.convertPoint(location, toView: topButton.viewForLastbaselineLayout), withEvent: nil) { topButton?.backgroundColor = UIColor.redColor() } else if bottomButton.pointInside(self.view.convertPoint(location, toView: bottomButton.viewForLastbaselineLayout), withEvent: nil) { bottomButton?.backgroundColor = UIColor.redColor() } super.touchesBegan(touches!, withEvent:event)}override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { let touch = touches.first let location : CGPoint = (touch?.locationInView(self.view))! if topButton.pointInside(self.view.convertPoint(location, toView: topButton.viewForLastbaselineLayout), withEvent: nil) { secondToLastTouchedButton = lastTouchedButton lastTouchedButton = topButton lastTouchedButton?.backgroundColor = UIColor.redColor() } else if bottomButton.pointInside(self.view.convertPoint(location, toView: bottomButton.viewForLastbaselineLayout), withEvent: nil) { secondToLastTouchedButton = lastTouchedButton lastTouchedButton = bottomButton lastTouchedButton?.backgroundColor = UIColor.redColor() } else { lastTouchedButton?.backgroundColor = UIColor.whiteColor() } if secondToLastTouchedButton != lastTouchedButton { secondToLastTouchedButton?.backgroundColor = UIColor.whiteColor() } super.touchesMoved(touches, withEvent: event)}override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { let touch = touches.first let location : CGPoint = (touch?.locationInView(self.view))! if topButton.pointInside(self.view.convertPoint(location, toView: topButton.viewForLastbaselineLayout), withEvent: nil) { topButton?.backgroundColor = UIColor.whiteColor() } else if bottomButton.pointInside(self.view.convertPoint(location, toView: bottomButton.viewForLastbaselineLayout), withEvent: nil) { bottomButton?.backgroundColor = UIColor.whiteColor() } super.touchesEnded(touches, withEvent: event)}override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) { lastTouchedButton?.backgroundColor = UIColor.whiteColor() super.touchesCancelled(touches, withEvent: event)}


