-1

The title might be a little confusing, but is there a way I can Get this code to execute the moment I touch the uiview?

entry.transform = CGAffineTransform(scaleX: 0.975, y: 0.975)
    speech.transform = CGAffineTransform(scaleX: 0.975, y: 0.975)

I have a UIView that I want to simulate a button press. Currently, the way I have it set up, It only triggers once my finger has left the screen

func voiceTap(sender: UITapGestureRecognizer? = nil) {
    entry.transform = CGAffineTransform(scaleX: 0.975, y: 0.975)
    speech.transform = CGAffineTransform(scaleX: 0.975, y: 0.975)
    UIView.animate(withDuration: 0.2, delay: 0, options: UIViewAnimationOptions.curveLinear, animations: {
        self.entry.transform = CGAffineTransform.identity
        self.speech.transform = CGAffineTransform(scaleX: 0.975, y: 0.975)
    }, completion: nil)
}

How to I get the code outside of the animation block to trigger the moment my finger touches the UIView?

baxu
  • 303
  • 1
  • 4
  • 12
  • A tap is a tap. Change it to UIGestureRecognizer and switch its state and case changed you update whatever you need – Leo Dabus Jan 29 '17 at 04:48
  • Possible duplicate of [iOS Detect tap down and touch up of a UIView](http://stackoverflow.com/questions/19611601/ios-detect-tap-down-and-touch-up-of-a-uiview) – KSigWyatt Jan 29 '17 at 04:54
  • You may also want to disable `delaysContentTouchesInView` if you're finding there's a delay. This happens for things like content in scroll views. – brandonscript Jan 29 '17 at 05:28

1 Answers1

0

You need to implement the methods (touchesBegan: withEvent: etc) to detect the received touch in your UIViewController and check if the touch corresponds to the UIView of your interest. And from there you can trigger an action.

Check this thread how to implement the methods

Or this one

Community
  • 1
  • 1