touchesMoved を使用して画像を移動するだけです。
@interface TTImageView : UIImageView
{
CGPoint startLocation;
}
@end
@implementation TTImageView
- (id)init
{
self = [super init];
if (self) {
[self setBackgroundColor:[UIColor redColor]];
[self setUserInteractionEnabled:YES];
[self setFrame:CGRectMake(0, 0, 100, 100)];
}
return self;
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint pt = [[touches anyObject] locationInView:self];
startLocation = pt;
[[self superview] bringSubviewToFront:self];
//change the size of the image
CGRect frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, 150, 150);
[self setFrame:frame];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
CGPoint pt = [[touches anyObject] locationInView:self];
CGRect frame = [self frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[self setFrame:frame];
}
@end