我在iOS领域还很陌生,我不知道如何制作一个可以在任何时候激活的按钮:
答案 0 :(得分:0)
您可以简单地添加一个UIPanGestureRecognizer
识别器,然后检测何时是UIButton,这意味着手指正在过去。
@IBAction func handlePan(gestureRecognizer: UIPanGestureRecognizer) {
if gestureRecognizer.state == .Began || gestureRecognizer.state == .Changed {
let translation = gestureRecognizer.translationInView(self.view)
// note: 'view' is optional and need to be unwrapped
gestureRecognizer.view!.center = CGPointMake(gestureRecognizer.view!.center.x + translation.x, gestureRecognizer.view!.center.y + translation.y)
gestureRecognizer.setTranslation(CGPointMake(0,0), inView: self.view)
}
}
您可以使用情节提要中的IBAction
或将UITapGestureRecognizer
添加到按钮,然后以类似的方式创建一个handle函数。
希望这会有所帮助!