如何仅指定特定图像上的触摸

时间:2014-04-11 07:33:38

标签: objective-c uitouch

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

 UITouch * t =[touches anyobject];
CGpoint * point = [t locationinview:self.view];

If([t view]) == imageview {

Imageview.center = point;

}

}

1 个答案:

答案 0 :(得分:0)

检查图像矩形内的点:

if (CGRectContainsPoint(imageview.bounds, point)) {
    //point inside imageView frame
}

您还可以在该图像视图上设置手势识别器,只需用户触摸该特定图像即可调用所需方法,例如:

-(void)viewDidLoad {
    [super viewDidLoad];
    UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTouched:)];
    gr.numberOfTapsRequired = 1;
    gr.numberOfTouchesRequired = 1;
    [imageview addGestureRecognizer:gr];
}
-(void)imageTouched:(UITapGestureRecognizer*)recognizer{

    //image view touched
}