문제

나는 사용 중입니다 - (void) touchesMoved 내가 할 때마다 물건을하는 것 입력하다 특정 프레임,이 경우 버튼 영역.

내 문제는 프레임에 들어갈 때만 일을하고 싶다는 것입니다. ~ 아니다 손가락을 프레임 안에서 움직일 때.

내가 프레임 안에있는 동안 내 메소드를 한 번만 호출 할 수있는 방법을 아는 사람이 있습니까? 같은 터치 모브로 다시 들어가면 다시 한 번 다시 호출 할 수 있습니다.

고맙습니다.

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

다른 팁

Simply add a BOOL TouchesMoved를 체크인하고 터치 렌드로 재설정합니다

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

Uibutton을 사용해 보시고 인터페이스 빌더에서 '터치 드래그 Enter'연결을 사용하십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top