首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"touchesBegan“错误

"touchesBegan“错误
EN

Stack Overflow用户
提问于 2015-09-23 11:09:04
回答 2查看 256关注 0票数 0

我的代码:

代码语言:javascript
复制
var location = CGPoint(x:0,y:0) 
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
    let touch = touches.anyObject() as? UITouch 
    location = touch.locationInView(self.view) 
    Button.center = location 
}

在这一行中给出一个错误:

代码语言:javascript
复制
let touch = touches.anyObject() as? UITouch 

怎么修呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-09-23 11:49:56

代码语言:javascript
复制
Try this : - 

  override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

    for touch in touches {
    if let touch = touches.first as? UITouch {
                           if touch.tapCount == 2{
                                //Do Something here
                            }
                                             }
                          }
        }
票数 0
EN

Stack Overflow用户

发布于 2015-09-23 12:16:46

尝尝这个

代码语言:javascript
复制
if let touch = touches.first as? UITouch
{
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32737965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档