Я полагаю, вы подклассифицировали UIImageView - если вы этого не сделали, вам следует сделать это сейчас.Кроме того, убедитесь, что для .userInteractionEnabled изображения установлено значение YES!
Интерфейс:
@interface YourImageView : UIImageView
@property (nonatomic, assign) CGPoint originalCenter;
@property (nonatomic, assign) CGPoint touchLocation;
@end
Импламентация:
@implementation YourImageView
@synthesize originalCenter;
@synthesize touchLocation;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
self.originalCenter = self.center;
self.touchLocation = [[touches anyObject] locationInView:self.superview];
self.transform = CGAffineTransformMakeScale(1.5, 1.5);
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
CGPoint touch = [[touches anyObject] locationInView:self.superview];
CGFloat xDifference = (touch.x - self.touchLocation.x);
CGFloat yDifference = (touch.y - self.touchLocation.y);
CGPoint newCenter = self.originalCenter;
newCenter.x += xDifference;
newCenter.y += yDifference;
self.center = newCenter;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
self.originalCenter = CGPointZero;
self.touchLocation = CGPointZero;
self.transform = CGAffineTransformMakeScale(1.0, 1.0);
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event];
self.originalCenter = CGPointZero;
self.touchLocation = CGPointZero;
self.transform = CGAffineTransformMakeScale(1.0, 1.0);
}
@end
Вы, конечно, можете деформировать себя.transform = sth в анимацию, чтобы она выглядела лучше.;)