How to call a method only once during -(void)touchesMoved?

自古美人都是妖i 提交于 2019-12-02 04:38:52

You can use some attribute to check if the code was already called when you were entering specific area. It looks like highlighted state of p1 object (not sure what it is) may be appropriate for that:

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];
}

Simply add a BOOL that you check in touchesMoved and reset in touchesEnded

Morbo
if( CGRectContainsPoint([p1 frame],[touch locationInView:self.view])) {
   NSLog (@"Touch Moved over p1");
  if (!p14.isHighlighted) {
   [self action: p1];
   p1.highlighted = YES; 
   }
  }else {
   p1.highlighted = NO;
  }

try using a UIButton and use the 'touch drag enter' connection in Interface Builder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!