Why I Love UIKit
simple but easy
I don't want my ranting and complaining to give the impression that I dislike UIKit; quite the opposite in fact.
Here's a simple piece of code I just wrote:
self.brightnessLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
self.brightnessLabel.textColor = [UIColor whiteColor];
self.brightnessLabel.opaque = NO;
self.brightnessLabel.backgroundColor = [UIColor clearColor];
self.brightnessLabel.alpha = 0.3;
self.brightnessLabel.textAlignment = NSTextAlignmentCenter;
self.brightnessLabel.text = NSLocalizedString(@"Swipe to change brightness", @"");
[self.view addSubview:self.brightnessLabel];
[UIView animateWithDuration:1.0 delay:4.0 options:0 animations:^{
self.brightnessLabel.alpha = 0.0;
} completion:^(BOOL finished) {
[self.brightnessLabel removeFromSuperview];
self.brightnessLabel = nil;
}];
Beautiful, simple, and easy. UIKit automatically waits four seconds then performs the animations over one second. I don't have to setup a timer, run a timer loop, or remember to cleanup. If the view controller goes away before the animation starts? No problem. If it goes away before the animation completes? No problem.
But by far the best part is the animations themselves. With a few exceptions, I just change various control properties to whatever I want the end-state to be and UIKit interpolates from the current state of the properties to the new value, smoothly animating for the one second duration. When finished, I can easily remove the control.
Think about that for a second; UIKit needs to "freeze" the current values so my property changes aren't immediately visible, remember everything I change, then restore the original values and run a timer to adjust the controls to their new values. It even handles multiple concurrent animations with different timings and switching animations in the middle of an existing animation.
We rarely stop to consider the frameworks and tools we use. Basic UIKit animation may be old hat, but take a minute to admire and appreciate the beauty and simplicity. Recall the sense of wonder you once had.
Now go forth and make something great.
This blog represents my own personal opinion and is not endorsed by my employer.