버튼을 2 초 동안 누르고 있으면 사용자 정의 이벤트를 발생시키는 매우 간단한 UIButton 하위 클래스가 있습니다. 이를 위해, 나는 오버라이드 :continueTrackingWithTouch : withEvent : 연속적으로 호출되지 않음
//
// Mouse tracking
//
- (BOOL)beginTrackingWithTouch:(UITouch *)touch
withEvent:(UIEvent *)event
{
[super beginTrackingWithTouch:touch withEvent:event];
[self setTimeButtonPressed:[NSDate date]];
return (YES);
}
- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
[super continueTrackingWithTouch:touch withEvent:event];
if ([[self timeButtonPressed] timeIntervalSinceNow] > 2.0)
{
//
// disable the button. This will eventually fire the event
// but this is just stubbed to act as a break point area.
//
[self setEnabled:NO];
[self setSelected:NO];
}
return (YES);
}
내 문제는 "continueTrackingWithTouch는 : withEvent는"(이, 아직은 장치 작업에 할 수없는 시뮬레이터입니다)라고 불리는되지 않는 마우스는 실제로 이동하지 않는 한 . 그것은 많은 움직임을 취하지는 않지만 약간의 움직임을 취합니다.
두 경우 모두 "예"를 반환하면 연속 이벤트를 수신하도록 설정해야합니다. 이것은 시뮬레이터의 이상한 일입니까, 아니면 제가 잘못하고있는 것입니까?
참고 : userInteractionEnabled는 YES로 설정됩니다.
NOTE2 : beginTrackingWithTouch : withEvent로 타이머를 설정할 수 있습니다.하지만 단순해야하는 작업에 더 많은 노력이 필요합니다.