Search code examples
iphonerotationscrollviewcgaffinetransform

How do I rotate and then scale an image within a scrollview?


I want to scale an image after rotating it using CGAffineTransformMakeRotation. When I simply pass the imageview in viewForZoomingInScrollView, scaling does not work once I have rotated my image. Any ideas?Thanks.


Solution

  • You can put the image view within a UIView instance and then rotate that instance using CGAffineTransformMakeRotation. I had an image view as a subview of a scroll view. Then I did this,

    UIView * view = [[UIView alloc] initWithFrame:self.imageView.frame];
    [view addSubview:self.imageView];
    [self.scrollView addSubview:view];
    
    view.transform = CGAffineTransformMakeRotation(M_PI_2);
    

    Return the imageView as the view for zooming. It should work.