1
我有一個非常簡單的UIButton的子類,當按鈕被保持2秒時,它將觸發一個自定義事件。要做到這一點,我推翻: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:方法」不會被調用,除非鼠標實際移動。它並不需要太多動作,但確實需要一些動作。
通過在這兩個中返回「YES」,我應該設置爲接收連續事件。這是模擬器的怪異還是我做錯了什麼?
注意:userInteractionEnabled設置爲YES。注2:我可以在beginTrackingWithTouch:withEvent中設置一個計時器:但是對於那些應該很簡單的東西來說,這似乎更加努力。