如何通过触摸检测对象索引?

时间:2014-10-09 06:12:29

标签: ios swift touch

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

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

所以他这样做了,但是我怎么能写出来呢?

请帮我解决这个问题。

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

在22:00直接去,你会发现这个。

1 个答案:

答案 0 :(得分:2)

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

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

    if let myTouch = touches.first {

    }
}
相关问题