Touch View Function?

Discussion in 'iOS Programming' started by macRumorsUserX, Mar 6, 2015.

  1. macRumorsUserX, Mar 6, 2015
    Last edited by a moderator: Mar 6, 2015

    macRumorsUserX macrumors newbie

    Feb 2, 2015
    What is the easiest way (in Swift) to create a function that triggers a UI animation when one touches a view and another animation when you stop touching that view, so this is what i am trying to write.

    func TapView1(){
    //touching View1
                UIView.animateWithDuration(1.0, animations: {
                View1.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
    //stops touching View1
                UIView.animateWithDuration(1.0, animations: {
                View1.frame = CGRect(x: 50, y: 50, width: 50, height: 50)
  2. Ubuntu macrumors 68000


    Jul 3, 2005
    You should read up on UIGestureRecognizer (and more importantly it's subclasses like UILongPressGestureRecognizer & UIPanGestureRecognizer which might be useful here).

    If you read through the docs you'll see that the UIGestureRecognizer class has a state, which can vary from various values like "Began" (When the user initiated the gesture), "Changed" and "Ended" - all key points for you to apply your respective animations.

Share This Page