我想创建一个应用程序,在UILongPressGestureRecognizer手势被触发时可以拖放UIButton。UILongPressGestureRecognizer
我:
UIGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
而且
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:self.view];
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:
//NSLog(@"handleLongPress: StateBegan");
break;
case UIGestureRecognizerStateChanged:
if(location.y > 75.0 && location.x > 25 && location.x < 300)
button.frame = CGRectMake(location.x-25, location.y-15, 50, 30);
break;
case UIGestureRecognizerStateEnded:
//NSLog(@"handleLongPress: StateEnded");
break;
default:
break;
}
}
这一个按钮(即伊娃button
)的伟大工程。我怎样才能向handleLongPress函数发送正在按下的当前按钮?换句话说,我愿做类似下面,我在sender
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer:(id)sender {
CGPoint location = [recognizer locationInView:self.view];
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:
//NSLog(@"handleLongPress: StateBegan");
break;
case UIGestureRecognizerStateChanged:
if(location.y > 75.0 && location.x > 25 && location.x < 300)
sender.frame = CGRectMake(location.x-25, location.y-15, 50, 30);
break;
case UIGestureRecognizerStateEnded:
//NSLog(@"handleLongPress: StateEnded");
break;
default:
break;
}
}
工作。谢谢! – v0idless 2011-05-18 06:15:39
@ v0idless:欢迎。 – EmptyStack 2011-05-18 06:52:40