前言:我对swift和ios Dev非常陌生。请善待。
我想创建一个突出显示用户触摸区域的图像。
到目前为止,我有这个:
// Dictionary that holds my image view per touch
var allImgViews : [Int : UIImageView] = [:]
override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
{
var image = UIImage(named: "dot.png");
var imgView = UIImageView(image: image);
for fing : AnyObject in touches
{
let loc = fing.locationInView(self.view);
imgView.frame = CGRect(x: loc.x, y: loc.y, width: 100, height: 100);
self.view.addSubview(imgView);
// ----- PROBLEM -------
// need to find a way to store the touched point imgView ...
// such that when touchsEnded is reached, only the point ended will
// vanish. This will also allow for multitouching.
}
}
从这里我有touchesEnded方法(理论上)将使用键获取正确的imgView,并执行removeFromSuperview()方法,从而在用户抬起手指时删除图标。我无法找到一个好的密钥来解决这个问题。而且我不确定这是否是处理多点触控的正确方法。
感谢。