- (void)loadView
{
self.view=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 300, 400)];
self.view.backgroundColor=[UIColor redColor];
imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];
imageView.image=[UIImage imageNamed:@"h1.jpg"];
imageView.tag=100;
imageView.userInteractionEnabled=YES;
[self.view addSubview:imageView];
[imageView release];
UITapGestureRecognizer* tapges=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageView:)];
tapges.numberOfTapsRequired=1;
[imageView addGestureRecognizer:tapges];
[tapges release];
//长按
UILongPressGestureRecognizer*pressges=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longImageView:)];
[imageView addGestureRecognizer:pressges];
[pressges release];
//捏合
UIPinchGestureRecognizer*pinchGRer=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchImageView:)];
[imageView addGestureRecognizer:pinchGRer];
[pinchGRer release];
//旋转
UIRotationGestureRecognizer*rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationImageView:)];
[imageView addGestureRecognizer:rotation];
[rotation release];
//清扫
UISwipeGestureRecognizer*swipeGRer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeImageView:)];
[imageView addGestureRecognizer:swipeGRer];
[swipeGRer release];
//拖拽
UIPanGestureRecognizer*panGRer=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panImageView:)];
[imageView addGestureRecognizer:panGRer];
[panGRer release];
}
-(void)tapImageView:(UITapGestureRecognizer*)sender
{
}
-(void)longImageView:(UILongPressGestureRecognizer*)sender
{
}
-(void)pinchImageView:(UIPinchGestureRecognizer* )sender
{
//imageView
}
-(void)rotationImageView:(UIRotationGestureRecognizer*)sender
{
imageView.transform=CGAffineTransformMakeRotation(sender.rotation);
}
-(void)swipeImageView:(UISwipeGestureRecognizer*)sender
{
NSString*imageName=[NSString stringWithFormat:@"hi.jpeg",arc4random()%20+1];
}
-(void) pantapImageView:(UIPanGestureRecognizer*)sender
{
sPoint=[sender locationInView:imageView];
if (sender.state==UIGestureRecognizerStateBegan) {
sPoint=[sender locationInView:imageView];
}
CGPoint current=[sender locationInView:imageView];
float disx=current.x-sPoint.x;
float disy=current.y-sPoint.y;
imageView.center=CGPointMake(imageView.center.x+disx, imageView.center.y+disy);
}