UIButton에 대한 하위 클래스를 만들었으므로 탭에서 애니메이션 효과를 얻을 수있었습니다. 효과가 작동하지 않습니다. 작동하지 않는 것은 시도를 할 때 @IBAction 뷰 컨트롤러. 함수가 호출되지 않습니다. 내 점수 판에 하위 클래스를 단추 클래스로 설정했습니다. 나는이 원인을 모르겠어요 어떤 아이디어UIButton Subclass @IBAction이 작동하지 않음
@IBAction func test(sender: AnyObject) {
println("go")
}
:
import UIKit
class SpringyButton: UIButton {
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
*/
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.9, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
self.layer.transform = CATransform3DMakeScale(0.8, 0.8, 1)
}, completion: nil)
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.9, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
self.layer.transform = CATransform3DMakeScale(1, 1, 1)
}, completion: nil)
}
override func touchesCancelled(touches: NSSet!, withEvent event: UIEvent!) {
UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.9, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
self.layer.transform = CATransform3DMakeScale(1, 1, 1)
}, completion: nil)
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.9, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
self.layer.transform = CATransform3DMakeScale(1, 1, 1)
}, completion: nil)
}
}
내의 ViewController 내 IBAction를 : 여기에 내 코드입니까?
사이드 노트 : UIButton을 서브 클래 싱하는 것은 그리 좋은 방법이 아니므로 UIView를 서브 클래스 화하고 탭 제스처 인식기로 연결하는 것이 더 낫겠습니까?
감사합니다.
이 작업을 수행하려면 UIButton을 하위 클래스로 만들지 마십시오. 나는 그것을 행동이나 뭔가의 일부로 추가 할뿐입니다. – Fogmeister
@Fogmeister가 시도한대로, 애니메이션이 동작으로 올바르게 작동하지 않습니다. – mlevi
정상 동작으로 절대 수행 할 수 있습니다 : D 'touchUpInside','touchDownInside' 등에 대한 동작을 추가하기 만하면됩니다 ... BTW, I 버튼의 레이어가 아닌 버튼 자체를 변형합니다. – Fogmeister