touchesBegin&touchesMove Xcode的对象C的问题

所以当你按下并拖动时,我的应用程序就能正常工作。 我也有UIButtons在接口生成器中设置为触摸。

以及当你拖动你需要从UIButton的外部拖动。 你不能点击UIButton并拖动到另一个。

移动触摸:

码:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event touchesForView:self.view] anyObject]; CGPoint location = [touch locationInView:touch.view]; if(CGRectContainsPoint(oneButton.frame, location)) { if (!oneButton.isHighlighted){ [self oneFunction]; [oneButton setHighlighted:YES]; } }else { [oneButton setHighlighted:NO]; } // if(CGRectContainsPoint(twoButton.frame, location)) { if (!twoButton.isHighlighted){ [self twoFunction]; [twoButton setHighlighted:YES]; } }else { [twoButton setHighlighted:NO]; } 

}

TOUCHES BEGAN:

码:

 - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event touchesForView:self.view] anyObject]; CGPoint location = [touch locationInView:touch.view]; if(CGRectContainsPoint(oneButton.frame, location)) { [self oneFunction]; [oneButton setHighlighted:YES]; } if(CGRectContainsPoint(twoButton.frame, location)) { [self twoFunction]; [twoButton setHighlighted:YES]; } 

}

我想要能够点击任何button激发function,也能够从一个button拖动到另一个激发function。

所以基本上只要点击一个button并滑动手指就可以启动另一个button,而不必从button外面按下和滑动。

我想我很近,需要一点帮助。 希望这一点清楚。

谢谢。

尝试了不同的东西。 使用这个工作好得多:

 if(CGRectContainsPoint(myObject.frame, location) && lastButton != myObject) { 

用它touchesBegan&touchesMoved。