嗯,我想這是最好的說明我的意思:UIButton的Touch Drag/Exit命中區域的大小是怎樣的?
你可以清楚地看到,一旦我們觸動按鈕,並搬出了它,隨之而來的舉動,在事件觸發按鈕狀態從遠處改變。
雖然這種行爲對於所有UIButtons來說都很自然,但我無法谷歌解決方案來改變它。
有沒有辦法減少這種類型的UIButton靈敏度的命中區域?我希望它減少了,因爲我覺得按鈕足夠大,它將提供更好的用戶體驗以及上/下音效。
UPD:爲UIButton的以下重寫代碼被張貼在another thread:
- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
CGFloat boundsExtension = 25.0f;
CGRect outerBounds = CGRectInset(self.bounds, -1 * boundsExtension, -1 * boundsExtension);
BOOL touchOutside = !CGRectContainsPoint(outerBounds, [touch locationInView:self]);
if(touchOutside)
{
BOOL previousTouchInside = CGRectContainsPoint(outerBounds, [touch previousLocationInView:self]);
if(previousTouchInside)
{
NSLog(@"Sending UIControlEventTouchDragExit");
[self sendActionsForControlEvents:UIControlEventTouchDragExit];
}
else
{
NSLog(@"Sending UIControlEventTouchDragOutside");
[self sendActionsForControlEvents:UIControlEventTouchDragOutside];
}
}
return [super continueTrackingWithTouch:touch withEvent:event];
}
它改變使用拖動/拖出事件的點擊區域擴展,但按鈕向上/向下狀態切換完全和以前一樣。
似乎是這個問題的一個副本: http://stackoverflow.com/questions/14340122/uicontroleventtouchdragexit-triggers-when-100-pixels-away-從uibutton – 2013-04-30 18:51:43
是的,差不多,但提供的答案不會改變按鈕的向上/向下狀態。他們似乎依靠100.0f命中區域擴展的其他東西。 – Kai 2013-04-30 19:01:29