If you want to get a feel for the singleton pattern in C# one of the best resources I always revisit is on John Skeet’s (@jonskeet) website http://www.yoda.arachsys.com/csharp/singleton.html
I encourage you to read the above article to appreciate the little intricacies or requiring static constructor, BeforeFieldInit, volatile etc.
However: If you just want the easiest lazy evaluation solution in .net4+, then you’ve come to the right place.
Lazy<T> guarantees thread-safe lazy construction.
If I’d followed Jon’s notice, at the top of the page I linked to, I would have seen the post is now located here and moreover, he covers the Lazy<T> approach there.
In my previous post I showed you how to have the keyboard resign first responder status when Return is pressed.
A little tip: is that you don’t need to set the delegate in code like my previous post, you can use the connections pane and Crtl drag from the textbox delegate to the view controller in the Outlets section.
Still not good enough
I still had a little niggle about this keyboard covering my view, I really wanted to see what I was doing, so here’s my solution.
I move the view up by y amount of pixels (-120pixels in this sample).
Why negative 120? Well given that your y coordinate starts at 0,0 on the top left (i think I’ve just got a flashback of OS/2 having the origin at the lower left corner… shudder…) we move upwards.
Here is our beautiful UX before we start editing
When the keyboard presents after the textbox gains first responder status it’s now covered.
So we move the view up
When we’re finished we move it back down
So how did we implement this function?
We change the view frame to shift the y position, and we did it in an animation to give it a little jazz.. 0.6 seconds is a way too slow for my liking but it does really show off the animation for demo purposes.
Here is what it ends up looking like: