2013-02-27 33 views
1

例如,當我使用UIGestureRecognizer時,當用戶向右滑動時,我想要有一個UIAlertView詢問他是否真的想要執行正確滑動操作。確認UIGestureRecognizer?

我試過這樣做,但沒有成功。

+0

我認爲你可以UIGestureRecognizerState測試。 http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html – 2013-02-27 04:11:01

+0

檢查委託http://developer.apple.com/library/ios/#documentation/uikit /reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIGestureRecognizerDelegate – 2013-02-27 04:11:48

回答

1

做這樣的,

UISwipeGestureRecognizer *gesture1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)]; 
gesture1.direction = UISwipeGestureRecognizerDirectionRight; 
[yourView addGestureRecognizer:gesture1]; 

在行動方法,

-(void)didSwipeLeft:(UIGestureRecognizer *)gestureRecognizer { 
    UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Are you sure to commit with its action" delegate:self cancelButtonTitle:CKString(@"NO") otherButtonTitles:CKString(@"YES"),nil]; 
    [Alert show]; 
    Alert.tag=222; 
    Alert.delegate=self; 
    [Alert release]; 
} 

在AlertView代表

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 

    if(alertView.tag==222) { 
     if(buttonIndex==1) 
     { 
      //// Yes condition 
     } else { 
      ///// No condition 
     } 
    } 
} 
+0

好的,我明白了。所以你甚至不用擔心UIGestureRecognizer的屬性。基於標籤。它怎麼說222然後111? – ranjha 2013-02-27 04:18:37

+0

抱歉,我現在編輯了... – Venkat 2013-02-27 04:19:31

+0

哦,好的。非常感謝! – ranjha 2013-02-27 04:21:25

2

UIGestureRecogniser事件方法中,使用適當的標題/消息創建UIAlertView

UIAlertView的代表設置爲self,在alertView:didDismissWithButtonIndex:中可以根據用戶點擊的內容執行操作。

+0

看到我的問題是當在UIAlertView中檢測到按下哪個按鈕時,如何訪問UIGestureRecognizer狀態屬性?您可以請發佈這個部分的示例代碼? – ranjha 2013-02-27 04:15:19