Make Your Custom UITableViewCells Scroll Smoothly

We all need custom UITableViewCells with many subviews from time to time.

The lowest-hanging fruit you can do to make them scroll more smoothly is to reduce the amount of drawing and layouting taking place in the subviews:

cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;

These two lines made Moped scroll frame rates to go from about 30fps to about 45fps on an old iPod Touch! 60fps is much closer now.

There is a small caveat though: this method causes all the views inside the table cell to be rendered to a bitmap, which gets drawn on the screen quickly when your cell scrolls. However if you have cells with animating progress bar or similar, this won’t give you any improvements and might make things worse because the rasterized bitmap needs to be redrawn every time your progress bar updates.

Chaos Management

I’m a lazy nerd.

My office keeps accumulating various odds and ends. I have lots of cables, old HDDs, power adapters and similar stuff. I keep stashing them in a corner thinking I might need them one day. I never do.

Zenhabits has a great tips on how to declutter your home but it’s not easy to stick to it.

I just threw away six 3-D movie glasses. 6 Euros into the trash can…

Is Google Glass a Better Bicycle?

Since Google started accepting applications for the Glass developer program, there is been a barrage of blog posts about how great Google Glass is and how it will change mankind for good or about how unappealing it is to the masses and how it will destroy face-to-face conversations, depending on whose Kool-aid you tend to like better.

The truth lies probably somewhere in between, as it is almost always the case.

I really like how Dustin Curtis mentions Steve Jobs’ bicycle analogy but his argument that Google Glass is the better bicycle for our minds is probably a bit overambitious.

I agree, the holy-grail, a wearable and perfectly context-aware personal computing device which makes us smarter and more connected with the world is definitely a better bicycle for our minds, but in my eyes Google Glass is probably not that device yet. It still has to prove that it is at least consumer-friendly as the best of the crop smart phone and generally better bicycle for our minds at the same time.

It is without a doubt very interesting and hopeful first step but how and who will turn this idea into a consumer device is still open.

Maybe I would think differently had I the chance to experience one. I haven’t and I’d be genuinely happy to stand corrected.

How to make your UITabBarControllers and UINavigationControllers respect your auto-rotation choices

iOS 6 introduced many changes related to view auto-rotation, which basically aim to decouple view controller orientation from the device orientation. While this might sound counter-intuitive, it actually makes a lot of sense and allows for a finer grained control of view controller orientations: A UITableViewController in portrait orientation in a pop over contained by a view controller in landscape orientation on an iPad, for instance.

However the UINavigationController and UITabBarController do not seem to be implementing the new shouldAutorotate and supportedInterfaceOrientations APIs as expected: regardless of the values returned by your view controllers, they always allow any orientation!

The fix, fortunately, is quite simple and can be added to the standard UINavigationController and UITabBarController with a simple category, which forwards the values set by the topViewController and selectedViewController respectively.

Here are the two categories you can add at the beginning of your app delegate:

UITabBarController

@implementation UITabBarController (AutoRotationForwarding)

-(BOOL)shouldAutorotate
{
    if ([self.selectedViewController respondsToSelector:@selector(shouldAutorotate)]) {
        return [self.selectedViewController shouldAutorotate];
    }
    else {
        return YES;
    }
}

- (NSUInteger)supportedInterfaceOrientations {
    if ([self.selectedViewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
        return [self.selectedViewController supportedInterfaceOrientations];
    }
    else {
        return UIInterfaceOrientationMaskAll;
    }
}

@end

and UINavigationController

@implementation UINavigationController (AutoRotationForwarding)

-(BOOL)shouldAutorotate
{
    if ([self.topViewController respondsToSelector:@selector(shouldAutorotate)]) {
        return [self.topViewController shouldAutorotate];
    }
    else {
        return YES;
    }
}

-(NSUInteger) supportedInterfaceOrientations {
    if([self.topViewController respondsToSelector:@selector(supportedInterfaceOrientations)])
    {
        return [self.topViewController supportedInterfaceOrientations];
    }
    return UIInterfaceOrientationMaskPortrait;
}

@end

Hope this helps somebody

Keep your model objects and UITableViewCells separate

Brent Simmons has recently published the best explanation I’ve seen so far on why not to pass model objects to UITableViewCell subclasses.

Auto-Rotation woes for older projects on iOS 6

If you have an old project started back in the times of iOS 3, you might have noticed that your app stopped auto rotating starting with iOS 6.

It’s well known that there are various sensible changes to the auto-rotation API in iOS 6. But if you do support the new APIs and your app still does not auto rotate, the culprit might be much simpler that you think.

In my case it was simple not assigning the rootViewController property on the mainWindow in application:didFinishLaunchingWithOptions:. Just assign it properly and voila! It works.

This took me half an hour to figure out. I hope this post save someone couple of minutes.

Wil Shipley on “Success, and Farming vs. Mining”

Insightful piece on the software business, on steadily building something up vs. trying to make a quick buck:

Your idea sucks. No, I’m not calling you stupid — my idea sucks, too. All ideas suck, because they are just ideas. They’re worth nothing. My success is because I worked to make the idea real. A lot. All my life. Starting when I was 12, I learned to program, and I’ve programmed every spare moment since. I didn’t become a millionaire until I’d worked at it for eighteen years. There was no genius idea I had. I just kept working, hating what I did before, and working some more to make it better. The idea part is cheap. Try to think of an idea that’s actually worth something on its own. “I wish I’d thought up the web browser.” Bullshit. The web browser had been thought up at least twenty years before those high-energy frogs coded one up on NeXTstep (c.f. Dynabook, 1968). It was the actual shipping product they wrote that caused the internet revolution, not the idea.

SynthCam – Computational Photography on the iPhone

Marc Levoy, an electronics professor at Stanford, has published a cool app called SynthCam. The basic idea behind the app is to capture many (parallel) images, which are slightly shifted from each other, and recombine them to first increase resolution and to simulate a larger aperture. Being a direct result of ongoing research, it does not perform every time as expected and you have to be super careful about not tilting the camera while jiggling it around, but it is amazing never the less. This is going to be the stuff the future cameras are made of. Just replace unreliable jiggling around of the camera, with an array of a few hundred cheap and low resolution lens camera assemblies, on the back of something the size of an iPad as Ctein suggests, add the technology behind this small app and you’ve got your self a super-flat, high resolution, cheap camera, which can be shifted and refocused after you made the exposure. Exciting times that we live in…

Reasons to be Cheerful

Charlie argues, quite convincingly, why the world is in a better shape for a huge number of its (human) inhabitants than it was a decade ago. The ecological and environmental issues are missing from his summary, but other than that, what he does mention gives some hope for the rest he fails to mention. (via O’Reilly Rader)

Instagram

I like Instagram. The best camera is the one you have with you, as they say.