user3071579
user3071579

Reputation: 85

How do i shrink an image horizontally using CGAffineTransform?

I've been using CABasicAnimation to move around images. Now I need to take a view and shrink it horizontally. On the web I see some people using CGAffineTransform to shrink/grow images proportionally. I need the view to shrink horizontally ONLY. See image below:

enter image description here

Any help with this would be greatly appreciated!

Upvotes: 1

Views: 324

Answers (1)

Archy Will He
Archy Will He

Reputation: 9777

CGAffineTransformMakeScale(sx,sy) will do the work.

  CGAffineTransform a = CGAffineTransformMakeScale(0.4, 1.0);
  editingView.transform = a;

You can use [UIView animateWithDuration:animations:completion:]; if you want it to be animated.

CGAffineTransform a = CGAffineTransformMakeScale(0.4, 1.0);
[UIView animateWithDuration:0.5
                 animations:^{  
                    editingView.transform = a;
                 }
                 completion:^(BOOL finished) {
                    /* do something after the animation */
                 }];

Upvotes: 2

Related Questions