2016-04-05 122 views
1

我需要處理針對UITouchTypeStylus觸摸事件的特定操作,並對按鈕進行特定操作。使用UITouchTypeStylus處理Apple鉛筆觸摸事件

如果我點擊按鈕與蘋果鉛筆這兩個事件被觸發。

讓我知道,如何觸發只有UITouchTypeStylus觸摸事件時點擊按鈕與蘋果鉛筆? 或 如果我們觸摸按鈕或任何動作時,如何處理..甚至當它是手寫筆。

回答

1

最好的方法是覆蓋touchesBegan/Moved/Ended方法和塊或委託方法調用傳遞觸摸類型的UIButton子類。然後檢查觸摸類型並調用適當的功能。

0
(void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event 
{ 
    UITouch* touch = [touches anyObject]; 
    if ([touch type] == UITouchTypeStylus) 
    { 
     //your code... 
    } 
    else 
    { 
     return; 
    } 
    [super touchesBegan: touches withEvent: event]; 
} 
+0

**從審批隊列中:**我可以請你,請周圍添加您的源代碼中的一些背景。 僅有代碼的答案很難理解。 如果您可以在帖子中添加更多信息,它可以幫助提問者和未來的讀者。 – HDJEMAI