0

我的项目中有一个UIButton,单击按钮后,我在该按钮UIView的顶部显示一个,以使该按钮当时保持隐藏状态。当我touchesmoved按住该按钮并将手指移到重叠的UIView. 据我所知,如下所示:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

 UITouch *touch = [touches anyObject];

    if ([touch view] == uiview)
    {

        NSLog(@"Touches moved");
    }

但是当我按住按钮时它不会被调用,当我按下按钮时它会被隐藏,UIView而当我释放按钮时 uiview 会隐藏。请问有什么建议吗?

4

2 回答 2

3

我不明白你想做什么,但我建议你使用 UIGestureRecognizers 并将手势识别器添加到你的按钮。

尝试使用此代码。我已经在我开发的纸牌游戏中使用了它。使用长按手势移动卡片。希望我有帮助。

 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(addLongpressGesture:)];
 [longPress setDelegate:self];
 [YOUR_BUTTON addGestureRecognizer:longPress];

- (void)addLongpressGesture:(UILongPressGestureRecognizer *)sender {

UIView *view = sender.view;

CGPoint point = [sender locationInView:view.superview];

if (sender.state == UIGestureRecognizerStateBegan){ 

      // GESTURE STATE BEGAN

}
else if (sender.state == UIGestureRecognizerStateChanged){

     //GESTURE STATE CHANGED/ MOVED

    CGPoint center = view.center;
    center.x += point.x - _priorPoint.x;
    center.y += point.y - _priorPoint.y;
    view.center = center;

    // This is how i drag my views
  }

 else if (sender.state == UIGestureRecognizerStateEnded){

      //GESTURE ENDED
 }
于 2013-10-11T03:13:09.550 回答
0

您需要为重叠的 UIView 设置 view.userInteractionEnabled = NO。这会将动作发送到按钮。

于 2013-10-10T21:53:21.780 回答