views:

290

answers:

1

Probably a newbie question, but:

I have a UIImageView that zooms and translates using multitouch. The built in animation feature is very handy, and works great. However, now I want to draw on top of it. The problem is that anything I draw goes beneath the UIImageView. If I switch to UIImage, and draw it myself, then the animation doesn't work. (The image simply jerks to the new position.)

What is the simplest way to solve this?

My drawRect looks like:

- (void)drawRect:(CGRect)rect {
if (image == nil) {
 return;
}

CGContextRef c = UIGraphicsGetCurrentContext();

// We only animate when translating, not zooming.
if(!multiTouching && !didZoom){
 [UIView beginAnimations:@"PhotoViewAnimation" context:c];
 [UIView setAnimationDuration:0.5];
}

// Paint the image with the new size/location.
imageView.frame = CGRectMake(currentPos.x, currentPos.y, image.size.width*imageScaleFactor, image.size.height*imageScaleFactor);

// Draw something (in this case just a line you can't miss).
CGContextBeginPath(c);
CGContextSetRGBStrokeColor(c, 1, 1, 1, 1);
CGContextMoveToPoint(c, 100, 100);
CGContextAddLineToPoint(c, 200, 200);
CGContextDrawPath(c, kCGPathStroke);

if (!multiTouching && !didZoom) {
 [UIView commitAnimations];
}

// If we were zooming, then we're done zooming now.
didZoom = false;

}

Thank you in advance!

Zack

A: 

what class does this -drawRect: method belong to? Did you subclass UIImageView, or are you placing an instance of some new view class of your own over a UIImageView?

NSResponder
I subclassed UIView. From the .h file:@interface PhotoView : UIView {