iPhone - 触摸区域检测 [英] iPhone - Touch Area Detection
本文介绍了iPhone - 触摸区域检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个应用程序,我允许用户触摸行OR路径上方。我想做一些像用户应该能够点击线的20像素。我已经google了很多但没有找到任何东西。
I am creating an app in which I am allowing user to touch above the line OR path. I want to do something like the user should be able to tap around 20 pixels of the line. I’ve googled a lot but found nothing.
推荐答案
以下是我的一个程序中的一段代码:我在这里做了类似的事情。只要用户点击屏幕,就会出现图像。我将屏幕限制在某些区域,只有在水龙头注册的地方。希望这可以帮助你:!!
Following is a piece of code from one of my programs: Here I have done something similar. A image appears wherever the user taps on the screen. I have limited the screen to certain areas, only where a tap will be registered. Hope this helps you:!!
-(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
}
}
}
}
这篇关于iPhone - 触摸区域检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文