输入期间特定字符的文本字段动画
我有一个文本字段,它使用数字键盘进行输入,我想这样做,以便当用户输入数字时,文本字段会自动在第一个数字后面插入一个 ' (撇号),以及任何其他数字数字将跟在撇号后面。但为了使这一点引人注目,我希望撇号在停留在文本字段之前“弹出”并改变颜色。就像敲击键盘字母时的动作一样——它们会弹出一秒钟。
在我看来,有几件事要做,但我没有在网上找到任何帮助:
输入一位数字后收到通知(可以输入多于一位的数字,但会出现动画并显示附加数字将显示在撇号之后)。
将撇号添加到文本字段中。
以动画方式插入撇号,同时允许文本字段不断接受输入。
任何对库、代码或建议的指导将不胜感激。太感谢了。我有预感我应该使用 coco2d 但不知道如何开始。
I've got a textfield, which is using a numberpad for input, and I'd like to make it so that when the user types in a number, the textfield automatically inserts an ' (apostrophe) after the first digit, and any other numbers would follow the apostrophe. But to make this noticeable, I'd like to have the apostrophe 'pop up' with a change of color, before resting in the textfield. Much like the action of the keyboard letters when they're hit - they pop out for a second.
Seems to me there's several things to be done and I haven't found any help online with them:
Get notice after one digit is entered (more than one digit could be entered, but the animation would take place and the additional numbers would show up after the apostrophe).
Add the apostrophe into the textfield.
Animate the insertion of the apostrophe, while allowing the textfield to continually take in input.
Any direction to libraries or code or suggestions would be immensely appreciated. Thank you so much. I've a hunch I'm supposed to use coco2d but have no idea how to get started.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了一个解决办法,我想我会分享,以防有人感兴趣。为了监视输入,您可以使用:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
当用户触摸键盘时调用它,但是在处理字符或数字并将其显示到屏幕之前。唯一的问题是,在空文本字段上,如果用户按退格键,则不会调用此方法(即使不为空)。基本上是因为没有更改空文本字段来处理空字符串。
您还可以使用:UITextFieldTextDidChangeNotification,但它以相同的方式调用,并且不提供任何可使用的参数。
对于 2:我最终为这些标签制作了标签,并将它们放在我想要的文本字段上,并根据需要使用它们的属性。这有点乱,所以我实际上将文本字段分成了 2 个,并使用上面的方法在两者之间跳转。似乎大部分工作都很好,但处理退格问题仍未解决(例如,在文本中退格时如何移回第一个文本字段)。我正在考虑在键盘的那部分覆盖一个透明按钮。虽然看起来很乱。我将不胜感激任何更干净的想法。
所以,最终没有制作任何动画,这本来会更流畅。希望这有帮助。
I figured out a work around that I'd thought I'd share in case anyone is interested. For monitoring input, you can use:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
which gets called when the user touches the keyboard, but before the character or number is processed and put to screen. The only problem is that on an empty text field, if the user hits backspace this method doesn't get called (even if not null). Basically because there's no change to an empty text field to process with an empty string.
You could also use: UITextFieldTextDidChangeNotification, but it gets called in the same way and doesn't offer any parameters to play with.
For 2: I ended up making labels for these and putting them over the text field where I wanted, and playing with their properties as needed. It was kind of messy so I actually split the text field into 2 and used the above method to jump in between. Seems to work mostly well, but dealing with the backspace issue is still unsolved (how to move back to the first text field when backspacing through text for example). Am considering overlaying a transparent button on that part of the keyboard. Seems messy though. I would appreciate any cleaner ideas that are out there.
So, didn't end up doing any animations, which would have been a much slicker. Hope this helps.