2016-12-02 8 views

답변

0

터치 이벤트를 버튼으로 전처리 할 이유가 없습니다. 당신은 버튼

의 IBAction를 지금 :)

애니메이션처럼 당신이 느끼는 중 재산 수정할 수 있습니다, 버튼의 레이어의 위치 속성을 애니메이션하고 여기, 당신의 ViewController의있는 viewDidLoad에

let animation = CABasicAnimation(keyPath: "position") 
animation.duration = 2.0 
animation.fromValue = self.testView.layer.position 
animation.toValue = CGPoint(x: self.testView.layer.position.x + 100, y: self.testView.layer.position.y) 

을 애니메이션을 선언 할 수 있습니다

self.yourButton.layer.add(animation, forKey: "position") 
//this is necessary, you have to set the position again once the animation complete as core animation simply removes the animate object from layer once animation finishes 
self.testView.layer.position = CGPoint(x: self.testView.layer.position.x + 100, y: self.testView.layer.position.y) 
//call your method do whatever you wanted to do once button tapped 
//example : lemme print my name 
print("sandeep") 
+0

위대한 답변입니다. 감사. Sandeep, 다른 처리도하고 있습니다. –

1

버튼을 누르면 다음 작업이 실행됩니다.

@IBAction internal func buttonTouchDown(_ sender: AnyObject) 

그리고 손가락을 뺄 때 (이 버튼을 누르면) 호출됩니다.

@IBAction internal func buttonTouchUpInside(_ sender: AnyObject) 

첫 번째 작업에서는 애니메이션을 시작할 수 있으며 두 번째 단계에서는 애니메이션을 끝내고 나머지 코드를 수행 할 수 있습니다. 다른 제스처가 필요하지 않으면 충분합니다.