我正在创建一个按钮编程和CGAffineTransform
不起作用在我的项目中,当添加在addTarget
,为什么?Swift 3 - CGAffineTransform不起作用
编辑:
func createButtonPuzzle(id: Int) {
for i in 1...14 {
let btnButton = UIButton(type: .roundedRect)
btnButton.frame = CGRect(x: self.view.frame.size.width/2, y: self.view.frame.size.height/2, width: 100, height: 100)
btnButton.backgroundColor = .blue
btnButton.setTitle("iButton", for: .normal)
btnButton.addTarget(self, action: #selector(moveButton(sender:)), for: .touchUpInside)
view.addSubview(btnButton)
}
}
func moveButton(sender: UIButton) {
if sender.tag == 1 {
if sender.transform == CGAffineTransform.identity {
UIView.animate(withDuration: 0.5, animations:
sender.transform = CGAffineTransform(translationX: 50, y: 100)
})
}
}
}
是使用自动布局或自动尺寸定位的看法?这可能不适用于自动布局。 – Sulthan
不使用自动布局或自动调整,它已经工作,但现在不起作用! @Sulthan –
你有没有设置断点?你知道它是否真的达到了转变?为什么你需要'moveButton'的参数名? – dfd