我想創建一個應用程序,在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