我正在创建一个应用程序,我允许用户触摸行OR路径上方。我想做一些像用户应该能够点击该行的20个像素的东西。我搜索了很多但没有找到任何东西。
答案 0 :(得分:1)
以下是我的一个程序中的一段代码:这里我做了类似的事情。只要用户点击屏幕,就会出现图像。我将屏幕限制在某些区域,只有在水龙头注册的地方。希望这可以帮助你:!!
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
image=[UIImage imageNamed:@"anyImage.gif"];
newView = [[UIImageView alloc]initWithImage:image];
if (location.y<117 || location.y>354)
{
newView.frame = CGRectMake (location.x, location.y,87,70);
newView.center=location;
[self addSubview:newView];
}
if (location.y<90)
{
if(location.y>85)
{
if (location.x>133 || location.x<183)
{
[self shakeA]; //A method shakeA is called
}
}
}
else if (location.y<360)
{
if (location.y>354)
{
if (location.x>133 || location.x<183)
{
[self shakeB]; // Method shakeB called
}
}
}
}