Simple example of CALayer usage — perhaps in a UIT

2019-07-06 14:48发布

问题:

I have an requirement to implement a custom keyboard for a Cocoa Touch data entry screen containing multiple UITextFields. I've built the keyboard, and everything is working except now I need to figure out how to implement a blinking cursor. (When you disable the UITextField's built-in keyboard, you lose the cursor as well). In googling around, I've seen a few mentions of using CALayer animation to do this. However, I have not yet found a simple example of how I might implement this. Since UITextField inherits from UIView, I was hoping I could use the text fields view as the host layer. The animation part of the blink is not what is worrying me, it is just setting this up properly. Any advice, or pointers to other sites containing a simple tutorial? (everything I've found has been oriented toward multi-layers and games, and not built on top of a basic view/textfield).

回答1:

You would have had to basically cycle a animation of a black CAlayer's opacity property from 0 to 1 repeatedly, but now you have custom input views https://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/Text/Text.html#//apple_ref/doc/uid/TP40009370-CH8