栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

迅速,轻触UIButton并轻触另一个

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

迅速,轻触UIButton并轻触另一个

我设法通过覆盖下面的功能并跟踪哪个按钮最后被触摸和倒数第二来创建合适的解决方案。触摸的最后一个按钮突出显示,倒数第二个按钮未突出显示。这是我进行两键测试的代码,以防有人发现它有用:

@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)}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380912.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号