When dismissing a modal causes your view to drop 20 pixels…
Today, I ran into a problem where I have a view displaying and I present a modal. Everything is fine, but when I dismiss the modal, the original view has now moved up about 20 pixels — very noticeably the height of a status bar.
I’ve run into this problem a few times during a few different projects. Each time, I did some quick investigation, but time pressure and opportunity induced me to just make a quick workaround fix instead. The problem has been that while I’ve seen a ton of developers report the problem, there are still no solutions!
Well, I was able to remedy it. I can’t tell you what the underlying problem is (iOS is closed source), but I eventually fixed it by pulling things and out and eventually comparing to a new iPad project. All of this happened after a couple of hours of tweaking code and my XIB with no success. In my mind, this was something deeper and out of my control, perhaps the tools.
My first hypothesis was that the XIB was being corrupted by Interface Builder. So, I created a new XIB to hook up to the view controller. I kept it empty except for a search bar at the top simply so I could gauge if it was displaying right. To my shock, even this XIB was moving down! What?!
So, I determined that it must be a problem with the UIWindow XIB. I created a new iPad project and compared it with all of the top-level pieces of my app. Everything was the same. The top level view wanted to be full screen, the size was the same, everything. What gives?
And here’s where I found my answer. It came from a hail mary, really. I noticed that whenever I’ve run into this issue, it’s always the top-level view that drops down the 20 pixels. Children always behave as expected. And so, the one difference between my app and the new app is that the new app creates the top level view controller from the UIWindow as it outlets it. I create it with code. I changed my strategy so that instead of creating the top-level view controller via code, I did it the same way and…
IT WORKS!!!!!!!!
This makes no sense to me. Something in Apple’s code, probably the timing where the view controller is created in relation to the window, at the same time versus later, seems to be misunderstanding the Y=0 position in relation to the status bar. I simply can’t identify what the bug probably is.
Yet, it does tell me what some people see it and some don’t. I generally create new projects as Window-based rather than View-based. With View-based projects, Apple creates the view controller in the XIB. I’m willing to bet the iOS developers who see this bug are creating theirs in code.
So, give it a try and lemme know. :-)
Do you have clients — or customers?
Read an interesting article last week (though I’ve lost track of it now) that asked the question if consultants have “clients” or “customers”. At first, the question seemed like on of terminology, but it really goes to the point of how you treat your business partners.
I’ve historically used the term client. My clients. Why? I don’t know why. It’s just industry slang I’ve picked up over time. I represent them. I work for them, but I’m not an employee to their business.
However, now, I’m in agreement that they are customers. For one thing, I am performing a service for them and am (hopefully) doing it in a way that makes them want to come back to me for future work. They are attracted to my business through referrals or finding my work online. That’s a customer to me, but also sounds like a client.
The difference? We aim to *satisfy* our customers. We merely *work* with clients.
From now on, my clients are now my customers.
Use Latest iOS
One of the quiet new features in the newest XCode release is a new BaseSDK option “Use Latest iOS”. Not all iOS developers will appreciate this unless they’ve been developing for at least 6 months or so.
The problem Apple has solved was an infuriating one. Since an XCode project (a target specifically) can only have one Base SDK, and since the newest SDK changes every couple months or so, we’re constantly loading up old projects (or sample code) and being met with the dreaded “Base SDK Not Found” message. ARGGGGGGGGGGG!!!!!
So, for example, say you want to run an old project to see how you implemented your camera code or something like that. You load the project, but it was running on iOS 4.0. The new XCode only has 4.1. So, no Base SDK found! You have to double-click the target (or targets), and change the Base SDK to the newest one. In fact, 99% of the time, you *always* want the newest one.
Now, as of the newest XCode, you can set the Base SDK to “Use Latest iOS” and, in theory, you’ll never have to change it again unless you have a perverse need to keep your app held back to an older SDK — in which case you are hanging on to an older XCode, too.
I say — thank you, Apple! One day, you’ll figure out how to include old SDK’s in the newest XCode builds, but in the meantime this does save me some grief! :-)
The Fred (1.e4 f5 2.exf5 Kf7??)
A little break from development, I have something to share from my love of chess. :-)
Many years ago, a friend of mine at our local chess club discovered The Fred in a book. I’m not sure what book, but suffice to say it probably wasn’t the MCO! It’s the most ridiculous defense I’ve ever seen given a moniker. I recall trying to explain it to my girlfriend and I couldn’t stop laughing — she’d just give me an odd look.
For many weeks thereafter, just for fun, we’d play it against each other in hopes of a victory that would be one for the ages. (And we were bored.)
Tonight, out of the blue, I decided to play this line again on Lichess. Whomever I was playing must have had feelings of annoyance when they saw it. That they were playing a young child perhaps. I actually hadn’t considered playing this over the Internet before, and I think you lose something in translation not being able to look in your opponent’s eyes and try to keep a straight face. :-) However, there was an amazing amount of satisfaction in taking this line into a very strategic, locked, defensive battle which would eventually break him/her. I wish I could talk with my opponent, who seemed like a good chess player, and ask them their feelings after confronting this defense and, ultimately, losing to it.
Tonight, I share with my chess fans, victory with The Fred defense!