-1

How do you animate only the contents of a UIImageView? If the image view is centered in the middle of the screen how do you animate the image to slide in from the left but only be shown within the frame of the image view?

As if you are looking at a wall with a window and someone walks by. You don't see them until they are in the frame of the window.

The code below certainly does not do it. I had it a few days ago with ease and erased it and now I can't remember how I did it. It was pretty simple but now it's driving me crazy.

        self.lockImages[button.tag].center.x -= self.lockImages[button.tag].bounds.width


        UIView.animateWithDuration(2.0, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1.0, options: nil, animations: { () -> Void in

            self.lockImages[button.tag].center.x += self.lockImages[button.tag].bounds.maxX


        }, completion: { (Bool) -> Void in


        })
Max Phillips
  • 6,991
  • 9
  • 44
  • 71

1 Answers1

0

UIImageView a subclass of UIView, inherits the .clipsToBounds() method, which will create the desired effect.

Acoop
  • 2,586
  • 2
  • 23
  • 39