iPhone 自定义键盘

发布于 2024-09-13 00:43:38 字数 414 浏览 2 评论 0原文

我正在创建一个自定义键盘,其中 10 个 UIButtons 排列在水平行中。这些按钮横跨屏幕宽度,大小相同,并且必须彼此齐平。

我还想允许用户通过沿着按钮行滑动手指来选择按钮。所选按钮的预览显示在屏幕上的其他位置。当用户沿着行移动手指时,预览会更新。当用户对他们的选择感到满意时,他们会松开手指,确认选择。

明显要尝试的是 UICountrolEventDragExit 或 UIControlEventDragOutside 来删除上一个按钮的操作,以及 UIControlEventTouchUpInside 来激活当前按钮并终止以前的触摸事件。然而,UICountrolEventDragExit 和 UIControlEventDragOutside 仅当用户将鼠标拖离给定按钮足够远时才会激活。由于我的按钮必须彼此齐平,这对我来说太远而且不够好。

建议?

I'm creating a custom keyboard with say 10 UIButtons laid out in a horizontal row. The buttons span the width of the screen, are the same size and must sit flush against each other.

I would also like to allow the user to choose a button by sliding a finger along the row of buttons. A preview of the chosen button is displayed elsewhere on the screen. The preview updates as the user moves their finger along the row. When the user is happy with their choice they release their finger, confirming the selection.

The obvious thing to try is UICountrolEventDragExit or UIControlEventDragOutside to remove the action of the previous button and UIControlEventTouchUpInside to activate the current button and kill previous touch events. However UICountrolEventDragExit and UIControlEventDragOutside are only activated when the user has dragged sufficiently far from the given button. Since my buttons must sit flush against each other this is too far and not good enough for me.

Suggestions?

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

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

发布评论

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

评论(3

哭泣的笑容 2024-09-20 00:43:38

禁用用于显示按钮的视图上的用户交互,并通过包含视图跟踪所有触摸。这与苹果键盘代码的工作原理类似。

(或者,您可以直接在单个键盘视图的 drawRect: 中绘制所有按钮,但这在方向更改期间看起来不正确)

Disable user interaction on the views used to display the buttons, and track all touches through the containing view. This is similar to how Apple's keyboard code works.

(alternatively, you could draw all of the buttons directly in the drawRect: of a single keyboard view, but that won't look proper during orientation changes)

述情 2024-09-20 00:43:38

如果您想要一个 10 个按钮的“键盘”,我会考虑使用 UISegmentedControl。您可以创建一个包含 10 个段的段,每个段都有自己的密钥,并以编程方式接收选择的密钥,如下所示:

 segmentSelected = mySegmentControll.selectedSegmentIndex;

If you want a 10 button 'keypad' I would look at using a UISegmentedControl. You can create one with 10 segments each with its own key and receive the key selected programatically like:

 segmentSelected = mySegmentControll.selectedSegmentIndex;
画骨成沙 2024-09-20 00:43:38

调用

-(void)touchesBegan:(NSSet )touches withEvent:(UIEvent)event;

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

明智地使用显示 10 个 UIImages(不是 UIButtons)的视图也可以正常工作。

Calling

-(void)touchesBegan:(NSSet )touches withEvent:(UIEvent)event;

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

judiciously with a view showing 10 UIImages (not UIButtons) also works fine.

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