【发布时间】:2011-05-18 05:45:29
【问题描述】:
我正在尝试创建一个应用程序,当触发 UILongPressGestureRecognizer 手势时,可以在其中拖放 UIButtons。
我有:
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;
}
}
这很适合一个按钮(即 ivar 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;
}
}
【问题讨论】:
标签: iphone objective-c ios