moving an instance of nsimageview...

So, I have a window designed in IB with a number of nsimageview elements that are then filled programmatically with what i want (it’s a scoreboard basically). currently it works well by just inserting a new image into the holder that refers to the correct position…

In order to make it more dynamic I thought that instead of doing that, i could have all the images predefined and then move and scale them to reflect their rank… But I have no idea how to do that…

In nsimageview, i can’t seem to see anything about their positions in the window or how to control that - am i barking up the wrong tree?

OLIx

You need to use drawInRect:fromRect:operation:fraction:, probably wrapped in lockFocus and unlockFocus call.

That is really interesting, will definitely look into that. Shane, what would be the equivalent for non NSImage objects, like NSRect or UI elements designed in IB? I’ve been wanting to animate UI elements for awhile now, just need a direction to look into… Thanks!

Browser: Safari 6533.18.5
Operating System: Mac OS X (10.6)

NSRects aren’t objects – they’re just descriptions of a position and size. I’m not sure hat you mean by UI elements. Anyway, you need to look at the Cocoa drawing guide. Deep breath…

If I’m understanding your question correctly, it seems that you can do what you want to do with methods like setFrameSize, setFrameOrigin or just setFrame. This code snippet illustrates this, using an animator to make it happen slowly.

property parent : class "NSObject"
	property iv1 : missing value
	property iv2 : missing value
	
	on applicationWillFinishLaunching_(aNotification)
		current application's NSAnimationContext's currentContext()'s setDuration_(2.0)
		iv1's animator()'s setFrame_({{300, 300}, {200, 200}}) --Can change both location and size like this or..."
		iv2's animator()'s setFrameOrigin_({100, 100}) --Change origin this way
		iv2's animator()'s setFrameSize_({20, 20}) -- Change size this way
		iv2's animator()'s setAlphaValue_(0) -- makes it disappear
	end applicationWillFinishLaunching_

iv1 and iv2 are IBOutlets for two image views.

Ric

That’s exactly what i want to do… Thank you so much…

OLIx

Thanks Ric, will definitely try this!

Shane, sorry my mistake. Not NSRect, I meant things like NSBezierPath and NSbuttons or NSPopUpButton, other elements that I would have dragged from the library in IB inside a view.

Could these be animated by the same tricks in NSAnimationContext? Or maybe NSAnimation?

Thanks!
Fred

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

If the docs say the class conforms to NSAnimatablePropertyContainer Protocol, it does; otherwise it doesn’t.

Hmmmm… Interesting. Thanks!

Browser: Safari 6533.18.5
Operating System: Mac OS X (10.6)