我想添加一个手势识别器到我的按钮,以便我可以运行代码,如果用户刷过按钮框架。如果滑动按钮向上,向右,向左或向下,我还希望此代码有所不同。如何初始化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