【问题标题】:How to detect object index with touch?如何通过触摸检测对象索引?
【发布时间】:2014-10-09 06:12:29
【问题描述】:

我正在开发一个益智游戏,我想检测发生触摸的图像的索引,我在 Objective-C 教程中这样做,它说:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
       UITouch* mytouch = [[ touches allObjects] objectAtIndex : 0 ];
       }

所以他是这样写的,但我怎么能写得这么快?

请帮我解决这个问题。

这是该教程的link 如果有人想查看更多信息。

22:00直接去就可以找到这个了。

【问题讨论】:

    标签: ios swift touch


    【解决方案1】:

    这是 swift 中的相同代码。请注意,touches 数组可以为空,first 属性返回可选值。这就是我使用可选出价的原因。

    override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
        let touches = touches.allObjects as [UITouch]
    
        if let myTouch = touches.first {
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多