Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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 在Swift中点击并按住UIButton?_Ios_Swift_Uibutton - Fatal编程技术网

Ios 在Swift中点击并按住UIButton?

Ios 在Swift中点击并按住UIButton?,ios,swift,uibutton,Ios,Swift,Uibutton,我试图得到一个UIButton来反复重复代码,直到用户释放按钮。我在一个游戏中有一个向上箭头,当它被点击时,一艘宇宙飞船将上升,直到它被释放。以下是我的按钮的代码: //at top of page let upArrow = UIButton() //in viewdidload() let upArrowImage = UIImage(named: "upArrow") as UIImage? upArrow.set

我试图得到一个UIButton来反复重复代码,直到用户释放按钮。我在一个游戏中有一个向上箭头,当它被点击时,一艘宇宙飞船将上升,直到它被释放。以下是我的按钮的代码:

    //at top of page
    let upArrow = UIButton()

    //in viewdidload()
         let upArrowImage = UIImage(named: "upArrow") as UIImage?
                upArrow.setImage(upArrowImage, forState: .Normal)
                upArrow.frame = CGRectMake(10, 220, 90, 40)
                upArrow.addTarget(self, action: "upArrowTouched:", forControlEvents: UIControlEvents.TouchUpInside)
                self.view?.addSubview(upArrow) 

//outside of viewDidLoad()
func upArrowTouched(sender:UIButton!){
            spaceship.position = CGPointMake(spaceship.position.x, spaceship.position.y + 3)
    }

有什么建议吗???

您需要为此实施自己的解决方案

1-用户触地(uicontrol事件触地),您开始每x秒/毫秒触发一次的时间

2-定时器将一次又一次地触发动作

3-用户润色uicontrol事件润色,取消计时器

因此,您将这两个事件绑定到不同的函数,并通过适当的操作启动/终止计时器

这有什么帮助

Daniel

可能重复的