【问题标题】:How can I specify a touch to be on a specific image only如何指定触摸仅在特定图像上
【发布时间】:2014-04-11 07:33:38
【问题描述】:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

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

If([t view]) == imageview {

Imageview.center = point;

}

}

【问题讨论】:

标签: objective-c uitouch


【解决方案1】:

检查是图像矩形内的点:

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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多