我正在通過長時間按住對象本身來設置遊戲對象的屬性。屬性的值由長按手勢的持續時間決定。我使用UILongPressGestureRecognizer爲了這個目的,所以它是這樣的:iOS:如何獲得長按手勢的持續時間?
[gameObjectView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handle:)]];
然後處理函數
- (void)handle:(UILongPressGestureRecognizer)gesture {
if (gesture.state == UIGestureRecognizerStateEnded) {
// Get the duration of the gesture and calculate the value for the attribute
}
}
如何獲得長按手勢的持續時間在這種情況下?
那麼是否有任何解決方法來獲得手勢持續時間? – 2012-02-23 19:28:08
檢查上面的代碼。希望它能爲你工作!如果您不使用ios 5,則可能需要進行一些更改。 – 2012-02-23 21:33:58
我避免爲此目的創建一個屬性,但我想沒有其他辦法。我使用NSDate而不是NSTimer,因此代碼可以更清晰。感謝您的回答! – 2012-02-24 05:32:44