0

I have a UIScrollview that zooms a PNG image in and out on a double tap. The way I have it set up, I create a few multiple sizes of the PNG image using UIGraphicsBeginImageContext/UIGraphicsEndImageContext and store all the UIImages in an NSMutableArray. I then show the correct image on screen by swapping a UIImageView's image to the correct UIImage based on the current zoom level (I do all this to show a nicely anti-aliased image at all times rather than scaling just the original image).

The problem I have is that the very first time the image gets swapped to one that hasn't been displayed before, there is a slight stutter. After the first time, I can zoom in and out all day and there is no stutter. I have tried the solutions suggested here and here but they did not fix the problem.

Currently, I found a workaround by swapping the image after 0.01 seconds, and canceling any pending swap requests in the meantime. This works ok but it's not a solid fix. Obviously there has to be a way to get the images in a ready state since they become ready after the first time they are displayed. Please help me!

Community
  • 1
  • 1
spybart
  • 2,583
  • 3
  • 22
  • 33

1 Answers1

1

You don't actually need to create different sizes of the png. What you should have is a UIImageView inside the scrollview with the original PNG as it's image. Then add this to your .m file (make sure you have in your header file.

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ return theImageView; }

you can also set the max and minimum zoom scale by doing this:

[scrollview setMinimumZoomScale:0.5];//will be half size
[scrollview setMaximumZoomScale:3.0];//will be 3X

Doing the above will automatically set up the pinch zoom for you. THen you just need to code in to listen for the double tap and tell it to do this:

[scrollview setZoomScale:1.0 animated:YES];//returns it back to original size

Hope this helps - let me know if not the effect you were looking for.

Cheers,

Michael

fatuous.logic
  • 750
  • 1
  • 5
  • 16
  • Also - if you do not want the pinch zoom stuff - leave out the -(UIView)viewForZoomingInScrollView function and just use the [scrollview setZoomScale:x animated:YES]; function on your double taps :) – fatuous.logic Apr 13 '11 at 08:45
  • Thanks for the response, but the reason I am not using this approach is that the resolution of my image is larger than the screen, and if I just use the original resolution and scale it down in a UIImageView, the image displayed does not look good (there is no pixel interpolation that takes place). I need my image to look good when it covers the entire screen as well as when I zoom into it. – spybart Apr 13 '11 at 18:54
  • 1
    Murat: Maybe you don't have your minification filter set? What is imageView.layer.minificationFilter set to? Try imageView.layer.minificationFilter = kCAFilterLinear. (see here: http://lists.apple.com/archives/cocoa-dev/2008/Feb/msg02070.html) – nielsbot May 02 '11 at 04:57