Last Revision:
Version 1.2, 2012-06-05
Updated for Mac OS X 10.7
(Full Revision History)
Build Requirements:
Xcode 4.0 or later, Mac OS X v10.7 or later
Runtime Requirements:
Mac OS X v10.7 or later

A small application that demonstrates how a view can implement the NSTextInputClient protocol. The view acts as a very simple text field, accepting character input and scaling the text to match its height. When the user enters a newline, the text fades away, hence the name "FadingTextView".

As a proper adopter of NSTextInputClient, FadingTextView supports "marked text". This is how the text system represents characters that may still be modified by user input, such as the accent that appears when typing Option-E on the standard U.S. keyboard. The accent is considered "marked text" until another character is entered. (This is also used extensively in input for some other languages such as Japanese or Chinese.)

At a few points, FadingTextView needs to access its input context. This is accomplished by calling the standard NSView -inputContext method, which does not usually need to be overridden.

FadingTextView uses the Cocoa text system (NSTextStorage, NSLayoutManager, NSTextContainer) for efficient drawing of its text. Many of the NSTextInputClient required methods also deal with the position of characters; FadingTextView converts the given points from screen to local coordinates and lets its layout manager do the rest of the work.

Rather than redraw the text at every point during the fade, the text is drawn once to a cache image. This image is then composited more and more transparently over a white background.

The fade-out is accomplished using an NSTimer, which will run in both the default run loop mode and the event-tracking run loop mode. This is so that the fade-out will continue even during a live resize.