MoreNotepad++

--------活出自己的精彩。

导航

IOS 实现可移动的UIImageView

//
//  MovableImageView.h
//

#import <UIKit/UIKit.h>

@interface MovableImageView : UIImageView

@end

  

//
//  MovableImageView.m
//

#import "MovableImageView.h"

@implementation MovableImageView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	[super touchesBegan:touches withEvent:event];
}


-(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent *)event
{
	[super touchesEnded:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
	[super touchesMoved:touches withEvent:event];
	
	float deltaX = [[touches anyObject] locationInView:self].x - [[touches anyObject] previousLocationInView:self].x;
	float deltaY = [[touches anyObject] locationInView:self].y - [[touches anyObject] previousLocationInView:self].y;
	self.transform = CGAffineTransformTranslate(self.transform, deltaX, deltaY);
}

@end

  

使用方法

MovableImageView* mv = [[MovableImageView alloc] initWithImage:vcDecorations.selectedImage];

[mv setUserInteractionEnabled:YES];

  

posted on 2014-01-23 15:38  MoreNotepad++  阅读(127)  评论(0)    收藏  举报