0

The first time a UIViewController gets presented there is a noticeable lag. The problem has been reduced to the UITextField, that is removing the UITextField removes the lag.

The lag only occurs the first time the UIViewController is presented (after launching the app). Subsequent times there is no lag. If you kill the app and relaunch it, the lag will appear again for the first presentation of the UIViewController.

This appears to be a known problem, but solutions proposed by other SO answers don't help. Unchecking the "Enabled" property in Storyboard doesn't solve the problem, for instance, nor does running the app not in the debugger.

Note: this isn't an issue with the keyboard appearing like in this SO question.

Any suggestions on workarounds?

Community
  • 1
  • 1
Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • Do you still Steve this behaviour when your app is not running under the debugger? – Paulw11 May 10 '16 at 20:40
  • @Paulw11 yes forgot to include that in the question. any ideas? – Crashalot May 10 '16 at 22:01
  • @Paulw11 also forgot to add that the lag only occurs the first time the UIViewController is presented (after launching the app). Subsequent times there is no lag. – Crashalot May 10 '16 at 22:19
  • Have you tried using the time profile instrument? – Paulw11 May 10 '16 at 22:26
  • @Paulw11 yes, but it didn't work. Found the problem: a custom font on the UITextField. Using the system font removes the lag. Any clues why? – Crashalot May 10 '16 at 22:34
  • I have seen that before with SpriteKit; If you haven't specified the font name exactly right then iOS goes through a complex process to try and work out which font you mean. This can cause big delays. – Paulw11 May 10 '16 at 22:35
  • @Paulw11 this isn't using SpriteKit. also the custom font was chosen via Storyboard (Gill Sans SemiBold). seen anything similar? – Crashalot May 10 '16 at 22:37
  • I understand that this isn't SpriteKit, I was just remarking that I have seen issues where searching the font catalog for a missing or mis-specified font causes delays. Just because you can choose a font from IB doesn't mean you have included that font in your app bundle, and this will cause a delay as iOS goes looking for it – Paulw11 May 10 '16 at 22:39
  • ok ... how do you ensure the font is in your app bundle? that would make sense if this is the problem. @Paulw11 – Crashalot May 10 '16 at 22:42
  • http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/ – Paulw11 May 10 '16 at 22:43
  • @Paul Cool will try, but can you confirm you're saying that something like "Gill Sans SemiBold", which is available via Storyboard, still needs to follow the procedures outlined in that blog post? If true, please post as an answer! – Crashalot May 10 '16 at 22:45
  • According to this http://iosfonts.com/ it should be available on iOS9 but not on iOS8 – Paulw11 May 10 '16 at 22:46
  • @Paulw11 from reading the blog how does it apply to something like Gill Sans SemiBold, which appears to be supported on iOS 8 (despite what iosfonts says) since the font does appear -- just with a slight delay? The blog post provides instructions on how to incorporate a custom font assuming you're the one supplying the font files. – Crashalot May 10 '16 at 23:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111581/discussion-between-paulw11-and-crashalot). – Paulw11 May 10 '16 at 23:55

2 Answers2

0

The problem was the presence of a custom font.

In other words, using the system font on the UITextField, rather than a custom font, removes the lag. No explanation why, but it works.

Crashalot
  • 33,605
  • 61
  • 269
  • 439
0

The use of custom fonts can cause delays if the font specification isn't quite right as it causes iOS to enumerate the fonts trying to find a match.

It seems that in this case the use of a font that has some differences between iOS8 and iOS9 caused the delay on iOS8 devices. Loading the font earlier in a non-critical section of code worked around the issue.

Crashalot
  • 33,605
  • 61
  • 269
  • 439
Paulw11
  • 108,386
  • 14
  • 159
  • 186