gpt4 book ai didi

objective-c - 通过触摸检测 View 内的更近点

转载 作者:行者123 更新时间:2023-12-01 16:54:18 24 4
gpt4 key购买 nike

有一种方法,当用户在 View 外触摸时,应用程序会检测到该 View 内更近的点?我想像下图一样检测。

Example

编辑:

CGPoint touchPoint = [[touches anyObject] locationInView:self.view];

if (CGRectContainsPoint([_grayView frame], touchPoint)) {
// The touch was inside the gray view
} else {
// The touch was outside the view. Detects where's the closer CGPoint inside the gray view.
// The detection must be related to the whole view (In the image example, the CGPoint returned would be related to the whole screen)
}

最佳答案

static float bound(float pt, float min, float max)
{
if(pt < min) return min;
if(pt > max) return max;
return pt;
}

static CGPoint boundPoint(CGPoint touch, CGRect bounds)
{
touch.x = bound(touch.x, bounds.origin.x, bounds.origin.x + bounds.size.width;
touch.y = bound(touch.y, bounds.origin.y, bounds.origin.y + bounds.size.height;
return touch;
}

关于objective-c - 通过触摸检测 View 内的更近点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13210670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com