我想添加一個手勢識別器到我的按鈕,以便我可以運行代碼,如果用戶刷過按鈕框架。如果滑動按鈕向上,向右,向左或向下,我還希望此代碼有所不同。如何初始化UIGestureRecognizer?
-(void)viewDidLoad
{
[super viewDidLoad];
UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(0, 0, 100, 100);
[self.view addSubview:button];
UIGestureRecognizer *swipe=[[UIGestureRecognizer alloc]initWithTarget:button action:@selector(detectSwipe)];
[button addGestureRecognizer:swipe];
}
那麼,我做了initWithTarget:action:
的事情是否正確?現在,我這樣做,我如何實施detectSwipe
方法?
這是我對如何實施detectSwipe
-(IBAction)detectSwipe:(UIButton *)sender
{
/* I dont know how to put this in code but i would need something like,
if (the swipe direction is forward and the swipe is > sender.frame){
[self ForwardSwipeMethod];
} else if //same thing for right
else if //same thing for left
else if //same thing for down
}
detectSwipe:沒有得到按鈕發件人。它是作爲參數傳入的手勢識別器 - 或者您還會如何知道識別器檢測到哪個手勢? – 2012-08-12 20:51:22