2013-02-27 88 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