0

I am trying to transform my UIButton left when clicked, and I want it to shrink at the same time as well. I have tried the following code, and it does transform left, but I do not know how to shrink the button. How could I shrink and transform the UIButton.

@IBAction func joinCircleButton(sender: AnyObject) {
    let button = sender as UIButton

    UIView.animateWithDuration(1.0, animations:{
        button.frame = CGRectMake(button.frame.origin.x - 75, button.frame.origin.y,button.frame.size.width, button.frame.size.height)
    })

}
Wain
  • 118,658
  • 15
  • 128
  • 151
StevenZ
  • 6,983
  • 5
  • 16
  • 18

1 Answers1

2

You can add this code inside your animation block. Which scale the button to half of its size.

button.transform = CGAffineTransformMakeScale(0.5, 0.5);
gabbler
  • 13,626
  • 4
  • 32
  • 44
  • That works thanks. But when I click on it a second time, it just goes off the screen. How would I prevent it from going off the screen? – StevenZ Jan 04 '15 at 08:28
  • Each time the button is shift left by 75 points, you should check `button.frame.origin.x - 75` to see if it is greater than 0. – gabbler Jan 04 '15 at 08:35