IKImageView is… odd

Apple made a really cool thing in Image Kit and IKImageView. It’s an amazing amount of power in very easy-to-use drop-in components.

Or so you would think.

I spent the weekend battling with IKImageView, and I’m still not getting exactly what I want.

Right now, it’s a matter of scrolling behavior. Take a look at how the Preview.app works. In general, it opens up an image such that the image is autosized to fill the window, keeping the image’s aspect ratio intact. If you resize the window larger or smaller, the image resizes accordingly, again maintaining the aspect ratio. Note however that scrollbars never show up. In general, this is good because it shows the whole of the image, even if it’s scaling down the image’s size, because most people want to view the whole image, not just part and then having to scroll around. But, if you do want to scroll around you can. You can use a function such as “zoom in” to get closer to the image, which should then make scrollbars appear (if the sizes are right), and you scroll from there. It works out great in Preview.app.

I wonder if Apple uses IKImageView in Preview.app or not, because I can’t get the same behavior.

But then I noticed something.

In the few bits of sample code there are about using IKImageView, the nib/xib file doesn’t actually embed an IKImageView within it. It has an NSScrollView then within that is merely an NSView. But in editing the NSView within the nib it gets a “custom class” setting typed in of IKImageView. So I tried that, because why was it working in demos but not in my app? So, mirror what you see in the working copy.

Things work.

Say what?

So I even try it in the demo app. Change the NSView to an IKImageView, rebuild. Things no longer work.

Holy crap.

So I try it in my app, using an NSView, changing the type to IKImageView. And lo… it works. It’s not 100%, some of the functions like “size to fit” aren’t calculating the numbers perfectly, but it’s a heck of a lot better.

Then I figured to try building it all by-hand in code instead of nib/xib files. I can’t get that to work. The app constantly crashes on me. As I isolate it down, it’s something about IKImageView.

Go figure.

I’ll work on filing bugs with Apple about this. None of it makes sense, and it’s damn frustrating. But there’s so little information out there about using IKImageView it makes it even more frustrating. So much power, so much potential, and it just falls flat. 😦

Updated: OK, color me really confused now.

I started to write up a bug report for Apple, using Apple sample code as a basis to demonstrate the problem. Sure enough, I was able to demonstrate some of the problems, such as IKImageView not being playing well with autohiding scrollers. But the other problems I was seeing, I now couldn’t get them to reproduce.

Eh?

So I went back into my app, gutted things, and started from scratch.

Now it works.

Eh?

Granted, there are still some bugs and problems with IKImageView itself, but now that it’s working is very strange. I did add some workarounds for issues (e.g. I just don’t auto-hide scrollers, I subclassed and added an -isFlipped override.), but man… very strange. I did note that at one point InterfaceBuilder fired an internal assertion failure, so something was out of whack for sure. Maybe the xib was corrupted somehow in all of this? Who knows.

Still, IKImageView is really awesome, I just look forward to all the kinks being ironed out.

5 thoughts on “IKImageView is… odd

  1. Thanks for that ScrollView with NSView masquerading as IKImageView tip!
    Turns out that it is indeed how Apple implemented it themselves… why?

    Btw did also manage to crash IB… while messing with the above.

    Zooming is now slightly better; as long as you don’t pan.
    IKImageView remains a broken tool… found a fix?

    • Nope. It’s still an odd duck. I don’t get it and things just are as they are.

      My recommendation to you? File a bug with Apple about this. The more developers we can get to raise the issue, that helps.

  2. Pingback: IKImageBrowserView pain « Stuff From Hsoi

  3. Dude, thanks so much for this post. That’s hilarious! I’ve been ticked trying to get a scrolling IKImageBrowserView to work all freakin weekend!

Comments are closed.