Strange and interesting text rendering phenomenon in UITextField with auto layout
Strange and interesting text rendering phenomenon in UITextField with auto layout
- Subject: Strange and interesting text rendering phenomenon in UITextField with auto layout
- From: Daniel Blakemore <email@hidden>
- Date: Tue, 23 Sep 2014 17:32:09 -0600
I was trying to fix some (what I thought to be) minor alignment bugs that
came up during QA for one of our apps, when I stumbled on one of the more
strange bugs I've seen recently.
In this app, the first screen presents you with the options to log in or
create an account.
The login screen is two text fields and the first part of the account
creation is one large one.
The QA came back with a bug where the email field on the login screen
wasn't properly centered during editing:
before tapping to edit:
after tapping:
At first, I couldn't even reproduce the bug until they gave me this set of
steps:
Launch the app
Look at the account creation screen (which sets the first textfield as
first responder automatically)
Go back the splash screen
Click the login button
start editing the text in the email box
voila, broken centering
After rounding up the usual suspects, nothing seemed to make sense. Plus
the only way to cause it was to view an unrelated view. Not only is the
account creation screen completely different from the login screen, but
once you back out of the account creation screen, it is deallocated and
shouldn't have any effect on anything.
Yet somehow, just having the cursor in the field was enough to spawn two
entangled particles somewhere in the depths of UIKit that linked this view
and the one that will be created (note it is not even in memory yet) when
the login view is initialized (and the original field has already been
deallocated). These two views that were never resident in memory at the
same time, used the magic of (presumably) quantum physics to communicate
across time and space with the goal of breaking my simple text centering.
After proceeding through the five stages of grief about what I assumed to
be yet another rare, unsolvable quirk in UIKit, I found this Stack Overflow
question:
http://stackoverflow.com/questions/24184302/uitextfield-horizontal-text-alignment-text-not-centered?rq=1
There was some mention that the height of the field affected the
centering. This isn't my issue because the field in question has a
reasonable height. But it got me thinking, what could have caused this?
I'm still not sure. But what I do know is that it only happens if you
start editing a UITextField where the height is set by a constraint such as
V:|-[viewInQuestion]-|. Once you begin editing that field (which itself
acts just as you would expect), you can edit the other field and observe
the jump:
This only happens the first time you begin editing the normally sized
field. Every subsequent entry into the field results in the normal
lack-of-crazy-jump that you've come to expect from UIKit. Additionally,
editing a similarly laid out text field with secureTextEntry set to TRUE
does not display the same behavior.
For now, I can change the constraint aligning the text field which is the
source of the problem, but I thought that this discovery might be of
interest to the cocoa-dev list (and hopefully to someone at Apple ;-] ).
As such, I created a new project from the ground up with a (mostly) minimal
setup to reproduce the bug under the conditions that I saw it (multiple
view controllers).
That project can be found here:
https://github.com/danblakemore/QuantumEntanglement
--
Daniel Blakemore
Pixio Software
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden