gpt4 book ai didi

ios - 减少 UIButton 的触摸区域

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:23:57 25 4
gpt4 key购买 nike

我正在尝试减少 UIButton 的触摸区域。这可能吗?当用户触摸按钮并将他的触摸拖到按钮外时,触摸事件应在按钮图形结束时立即停止。不幸的是,该区域比实际图形大得多。我发现了很多关于如何增加面积而不是如何缩小面积的东西。

感谢您的帮助。

最佳答案

我想到了一个解决方案。您可以子类化 UIButton 并重写 touchesMoved: 以便它识别触摸在按钮外部时结束。这是我的片段。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];

if(!CGRectContainsPoint(self.bounds, touchPoint))
{
[super touchesEnded:touches withEvent:event];
}
else
{
[super touchesMoved:touches withEvent:event];
}
}

这样做的缺点是,如果你离开按钮再回来,按钮就不会激活。但除此之外,我认为它应该可以正常工作。

关于ios - 减少 UIButton 的触摸区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12864093/

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