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

后端 未结 4 774
心在旅途
心在旅途 2021-01-27 02:02

I am using - (void) touchesMoved to do stuff when ever I enter a specific frame, in this case the area of a button.

My problem is, I only w

4条回答
  •  情歌与酒
    2021-01-27 02:30

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

提交回复
热议问题