如果我正确理解您的问题,您正在触摸一个按钮,该按钮包含在某个 UIView 中,并且希望能够将您的手指拖出并识别按钮超级视图中的点。
在我看来,您应该从按钮检测按钮按下,然后调用[UIButton superview]
, 告诉超级视图有关按下按钮的开始,然后在视图中处理触摸结束。
要通知按下的按钮的超级视图,请调用类似(来自您的 UIButton):
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.superview buttonPressed:self]
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self.superview touchesEnded:touches withEvent:event];
}
在您的超级视图代码中(如果您有属性 buttonPressed):
-(void) buttonPressed:(UIButton *) button {
_buttonPressed = button;
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if(self.buttonPressed) {
//Process the release from your drag here.
for(UITouch * touch in touches) {
//Use either of these to get the release position that you care about.
CGPoint releaseLocationInCurrentView = [touch locationInView:self];
CGPoint releaseLocationInButtonView = [touch locationInView:[self.buttonPressed]];
}
}
}