Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 临时创建ImageView-Swift中的多点触摸_Ios_Swift_Multi Touch - Fatal编程技术网

Ios 临时创建ImageView-Swift中的多点触摸

Ios 临时创建ImageView-Swift中的多点触摸,ios,swift,multi-touch,Ios,Swift,Multi Touch,前言:我是swift和ios开发人员的新手。请善待我 我想创建一个图像,突出显示用户触摸的区域 到目前为止,我有: // Dictionary that holds my image view per touch var allImgViews : [Int : UIImageView] = [:] override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { var image = UIImage(na

前言:我是swift和ios开发人员的新手。请善待我

我想创建一个图像,突出显示用户触摸的区域

到目前为止,我有:

// 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方法,从而在用户抬起手指时删除图标。我很难找到解决这个问题的好钥匙。我不确定这是否是处理多点触摸的正确方法


谢谢。

imgview仅存在于您的ToucheSBegind方法中。为了跟踪它,您需要将它声明为您正在使用的类的属性。然后你可以在你的类中的任何地方添加和删除它。如果我将它设置为全局,我将如何创建多个,并仅删除那些未被触及的。我不完全理解你想做什么do@hamobi我试图在用户触摸屏幕时创建一个图像。如果用户松开手指,图像应该被删除而不显示。然后使用imgview作为属性应该满足您的要求。你触摸屏幕。只需添加子视图,当您松开手指时,从SuperView中移除。这就是全部。