It started with this image. Or rather the glitch that you can see in the middle of the screen.
It’s one of the screens in a new app that I’ve been developing. There’s lots of hard stuff in there but this is the first problem that has really stumped me. What it appeared to be was this: a text view (UITextView) on a table (UITableView) showed a nasty glitch when you tried to place the curser in the text box.
First thoughts:
- Transparency
- Scrollview (UITextView) within a scrollview (UITableView)
- Image background
So I switched off the transparency. (No effect.) I switched off scrolling while editing. (No effect.) I made the background boring. (No effect.)
I was stumped.
I showed it to some guys at the London iOS Developer Group meeting. They too were stumped. (This was a bit of a relief. It meant that I wasn’t doing anything completely stupid, which is always a risk.)
So I tried writing a question for Stack Overflow. And, as I often do, I stumbled across the solution.
Note that the text view has a small border and rounded corners? Yup, that’s the culprit. Or at least, some of that code is. Here are the two lines that do it:
self.layer.cornerRadius = 5;
self.layer.shadowOpacity = 0.5;
(There were quite a few other lines adjusting the layer too, which is what took the time to narrow down.)
It was nothing to do with the table view or the text view per se. It wasn’t even any of the visible transparency effects.
Of course, in the screen I have no need for a shadow, indeed you can’t even see one, so the solution was easy. Quite why this combination causes such a weird effect have no idea, but I’m glad that I found the solution.
(I raised a bug report with Apple: rdar://11041657.)