質問

I m writing an APP so the user can draw over an UIImageView

He can also pinch on it for zooming in/out.

I have implemented an UNDO feature.

So every time the user draw a stroke or pinch the picture, i save the UIImage and the frame :

    ImageWithFrame *imageWithFrame = [[ImageWithFrame alloc]
    initWithImageAndFrame:imageViewSubject.image andFrame:imageViewSubject.frame];
    [self.tabImageForUndo addObject:imageWithFrame];

I tried to save the whole UIImageView in my array but it doesn't work, that is why i save the UIImage and the frame.

And after the user click on the UNDO button, i got the last imageWithFrame from the array

    ImageWithFrame *imageWithFrame = [self.tabImageForUndo lastObject];

And i do this :

    ImageWithFrame *imageWithFrame = [self.tabImageForUndo lastObject];

    self.imageViewSubject.frame = CGRectIntegral(imageWithFrame.frame);
    self.imageViewSubject.image = imageWithFrame.image;

    self.imageViewSubject.autoresizingMask = UIViewAutoresizingFlexibleWidth |     UIViewAutoresizingFlexibleHeight;

    [self.tabImageForUndo removeLastObject];

And i clear the graphic context just in case :

    UIGraphicsBeginImageContext(self.view.bounds.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextClearRect(context, self.view.bounds);

   // clean up context
   UIGraphicsEndImageContext();

======================================

My UIImageView appears, i do a stroke, i make an undo, it works.

And after I do a pinch, the UIImageView is resized (zoom out or zoom in) , i do an undo, so the UIImageView get back to its old frame.

BUT

If i draw another stroke, the picture get blurred and the UIImageView become smaller and smaller.

Look at this video http://tinypic.com/player.php?v=ivbkn5&s=5

I got the same effect (but on the whole UIImage, it is normal as the UIImage has been been redraw with the stroke)

It has been uploaded by another user, from this post : CGContextStrokePath not working when zooming and drawing images

But i don't think the source of its problem is related to mine.

PLEASE NOTE THAT If i don't do the pinch, it works perfectly, so i think the problem is when i set the old frame after a pinch gesture.

I hope i m clear enough.

Thanks a lot in advance :)

役に立ちましたか?

解決

I finally solved it by using

UIGraphicsBeginImageContextWithOptions(self.imageViewSubject.bounds.size, self.imageViewSubject.opaque, 0.0);

instead of

UIGraphicsBeginImageContext(self.imageViewSubject.bounds.size);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top