如何创建一个行为类似于 UIKeyboard(数字键盘)的 UIButton 矩阵?

发布于 2024-10-08 22:28:20 字数 214 浏览 0 评论 0原文

使用 UIButtons 创建一个简单的按钮矩阵非常简单。我所坚持的是它的行为。多个 UIButton 的行为不同。当触摸离开时,UIKeyboard 上的按键会失去突出显示状态,而自定义按键会在相当长的时间内保持突出显示状态,即使触摸位于外部也是如此。

此外,在 UIKeyboard 上,人们可以拖动触摸,从而激活不同的键, 如何在 Matrix 设置中使用 UIButtons 实现这一行为?

Creating a simple button matrix with UIButtons is straight forward. What I'm stuck with is the behavior of it. The multiple UIButtons behave differently. The Keys on a UIKeyboard loose their highlighted state when the touch leaves them, the custom ones keep their highlighted state for quite some time, even when the touch is outside.

Furthermore on the UIKeyboard one can drag the touch and thereby activate a different key,
how would one implement this behavior with UIButtons in a Matrix setup?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往事风中埋 2024-10-15 22:28:20

要执行类似 UIKeyboard 的操作,我建议根本不要使用 UIButtons,而只使用 UIView 并使用 TouchBegan: TouchesEnded: TouchMoved: 方法来确定用户手指的位置。

要在手指移动时选择按钮,您可以在容器内拥有其他视图,当手指在容器上移动时,这些视图将会更新。这可以通过在手指移动时进行点击测试来查看用户位于哪个 UIView 上,然后调整其视觉状态以显示它来完成。

To do something like the UIKeyboard I'd suggest not using UIButtons at all, and instead just use a UIView and use the touchesBegan: touchesEnded: touchesMoved: methods to determine where a user's finger is.

To select buttons as a finger moves around, you could have other views within the container that would be updated when the finger moves over it. This can be accomplished by doing hit tests as the finger moves around to see which UIView the user is over, then adjusting its visual state to show it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文