我在用- (void) touchesMoved
每当我做某事enter特定的框架,在本例中是按钮的区域。
我的问题是,我只希望它在我进入框架时做一些事情 -not当我在框架内移动手指时。
有谁知道我如何在框架内时仅调用一次方法,并且如果我在同一个 touchMove 中重新输入它,仍然允许我再次调用它。
谢谢。
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint location = [touch locationInView:touch.view];
if(CGRectContainsPoint(p1.frame, location))
{
//I only want the below to me called
// once while I am inside this frame
[self pP01];
[p1 setHighlighted:YES];
}else {
[p1 setHighlighted:NO];
}
}
您可以使用某些属性来检查当您进入特定区域时是否已经调用了该代码。它看起来像突出显示的状态p1
对象(不确定它是什么)可能适合:
if(CGRectContainsPoint(p1.frame, location))
{
if (!p1.isHighlighted){ // We entered the area but have not run highlighting code yet
//I only want the below to me called
// once while I am inside this frame
[self pP01];
[p1 setHighlighted:YES];
}
}else { // We left the area - so we'll call highlighting code when we enter next time
[p1 setHighlighted:NO];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)