gsempe
gsempe

Reputation: 5499

Enable zoom of UIScrollView reset zoomed view transformation

First, I would like to precise that it seems there is lot of questions on this subject with no response. The one who gets this answer should be rare.

I set an UIImageView as a zoomed view in a UIScrollView subclass.

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imageView;
}

Just after self.imageView creation I apply a CGAffineTransform on it and it's matrix is changed from :

(CGAffineTransform) $0 = {
  (CGFloat) a = 1
  (CGFloat) b = 0
  (CGFloat) c = 0
  (CGFloat) d = 1
  (CGFloat) tx = 0
  (CGFloat) ty = 0
}

to

(CGAffineTransform) $2 = {
  (CGFloat) a = 0
  (CGFloat) b = 1
  (CGFloat) c = -1
  (CGFloat) d = 0
  (CGFloat) tx = 0
  (CGFloat) ty = 0
}

After several calls of the - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView delegate method the transformation matrix of self.imageView is changed from :

(CGAffineTransform) $6 = {
  (CGFloat) a = 0
  (CGFloat) b = 1
  (CGFloat) c = -1
  (CGFloat) d = 0
  (CGFloat) tx = 0
  (CGFloat) ty = 0
}

to

(CGAffineTransform) $7 = {
  (CGFloat) a = 0.130719
  (CGFloat) b = 0
  (CGFloat) c = 0
  (CGFloat) d = 0.130719
  (CGFloat) tx = 0
  (CGFloat) ty = 0
}

As you can see 0.130 is my zooming scale but my rotation transform disappears.
I'm searching for a way to keep the rotation on self.imageView.

Very Thank you for your help.

Upvotes: 0

Views: 612

Answers (1)

Stephane Philipakis
Stephane Philipakis

Reputation: 138

It probably sounds a bit Hack'ish but what I would try to do is embed the imageView in a UIView that will be returned by the viewForZoomingInScrollView call.

This way, the imageView will retain it's rotation transform while it's superview will be scaled up or down.

I tend to avoid making assumptions on what does UIKit internally

Upvotes: 4

Related Questions