This article is more than 1 year old

Apple's ImageKit exposed

Inside view

Strictly speaking, those are the only delegate methods supported by IKImageView, but - like I said - other classes can potentially get in on the act. An internal class (IKComposer, if you're curious) will also examine the specified delegate object to see what delegate methods it supports. At this point, I'd like to thank Jim Turner for giving me a pointer on this one. Jim's a Cocoa Mac programmer from Iowa who I met and have been talking to on an Apple mailing list for Cocoa developers.

The delegate methods discovered by Jim are:

-(void) imageWillChange: (IKImageView *) imageView;
-(void) imageDidChange: (IKImageView *) imageView;
-(void) imageDidChange: (IKImageView *) imageView 
           imageState: (IKImageState *) state
image: (CGImageRef) image;  
- (NSUndoManager *) undoManagerForOperation: (NSString *) operation;

If your delegate responds to the more complex imageDidChange: method, then the simpler one will never be called: The two are mutually exclusive. For more information on IKImageState and IKComposer, use class-dump. Jim and I have discovered that imageWillChange: is always called reliably, but this isn't necessarily the case for the imageDidChange: variants.

NSImageView

IKImageView, and more, can be found inside Apple's latest Preview

Delegate methods aside, there are plenty of other interesting aspects to IKImageView. Use these methods to get a checkerboard background in your image view:

- (BOOL) showsCheckerboard;
- (void) setShowsCheckerboard: (BOOL) showsCheckerboard;

As mentioned earlier, double-clicking on an IKImageView will invoke the image-editing panel. One quirk of the image-editing panel is that it stubbornly refuses to go away when you switch over to another application.0 If - like me - you don't like this behaviour, you can fix it using the code below:

[[IKImageEditPanel sharedImageEditPanel] setHidesOnDeactivate: YES];

Another interesting feature of IKImageView is the tool mode. Apple document a number of tool modes, but in addition to the official modes, I've also discovered those below:

IKToolModeSelectEllipse
IKToolModeSelectLasso
IKToolModePaste*

It's pretty obvious from the names what these do. Bear in mind that IKToolModePaste is somewhat unusual - hence the star. You can't set this tool mode in the normal way using the setCurrentToolMode: method.

Finally, a number of folks have pondered the easiest way of getting an NSImage into an IKImageView. The documentation states you can use an NSImage, but the official setImage:imageProperties: method expects a CGImageRef. So, what to do? It turns out that Apple neglected to document another method called, simply, setImage:. Just pass an NSImage to via setImage, and you're good to go.

[_myImageView setImage: [NSApp applicationIconImage]];

There's no demo application this week to show undocumented aspects of IKImageView and other classes lurking inside ImageKit so no homework for you. Hopefully, though, you've got a taster for what IKImageView can do for you. ®

More about

More about

More about

TIP US OFF

Send us news


Other stories you might like