jverkoey/nimbus — Issue #114: Sometimes NIAttributedLabel ignores fast touches
Author: mt19
Created: 2011-11-22 16:01:55+00:00
State: open

When user makes a fast touch on a link, NIAttributedLabel ignores this touch. If user makes a long touch - everything works as expected (highlighted link frame appears and disappears, touch is handled).

The issue is about - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event, - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event handlers and - (void)setNeedsDisplay method and how detection link at point is implemented.

To successfully detect link at point it's necessary to have _textFrame initialized. This variable is initialized in - (void)drawTextInRect:(CGRect)rect. And NIAttributedLabel resets _textFrame with setNeedsDisplay-method when its content is changed.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event calls [self setNeedsDisplay] (to draw a highlighted frame) also. And setNeedsDisplay resets _textFrame. And, when - (void)drawTextInRect:(CGRect)rect is not called between touchesBegan and touchesEnded -- _textFrame won't be initialized (this is a real case). As a result the fast touch will be ignored.

The possible solution is not to reset _textFrame in touchesBegan and touchesEnded handlers (I think that's safe because label content is not changed between calls of these handlers). For example, call just [super setNeedsDisplay] in the mentioned above handlers instead of [self setNeedsDisplay]. But probably, it would be better to wrap the super call in something more appropriate.

Thanks!