NSImageView Animation

Doing an UIImageView animation is dead simple....
but I can't for the life of me figure out how to do a NSImageView

I am attempting an app for both macOS/iOS
and am using typealias to swap in the proper object types (NS vs UI)

compiling for iOS this works in then init routine for a UIImageView

self.animationImages = [aliasIMAGE(named:"fixedLASER00")!,aliasIMAGE(named:"fixedLASER25")!,aliasIMAGE(named:"fixedLASER50")!,aliasIMAGE(named:"fixedLASER75")!]
self.startAnimating()

aliasIMAGE resolves to either NSImage or UIImage depending on which I'm compiling for
I don't mind using #if os(xxx) if the syntax for NSImageView is different, I just can't find any clear examples

while we are on the subject... I need to ROTATE them as well :)

First of all, this forum is for open-source Swift, not Apple-private frameworks and libraries like Appkit/Cocoa and UIKit/Cocoa Touch. You might get better luck on the Apple Developer site, or other Apple-specific development sites.

Appkit and UIKit are somewhat different because of architecture and age. You can't just substitute an NS for a UI, especially animation.

Using Xcode Help>Developer Documentation will get you to the documentation for all of the various Apple-private frameworks, or developer.apple.com.

I'm sorry... did I misunderstand this?

This area is intended for users to get help with or ask questions about Swift or its related tools. Beginner questions welcome!

This category is not for discussion about work being done to the language itself.

I realize you cannot just swap out NS or UI in a lot of cases, in many you can.

I had hoped that the attitude here was better than the egotistical Stackoverflow.. where the only answer given is RTFM..... For the record... I spent a number of hours searching for an answer,

But never mind... I will revoke my membership here and cease being a burden

Apple wants this forum to be about open-source Swift, not an Apple programming site. It's in the founding rules. Your questions are about Apple programming, not Swift. You could have asked the same questions about the Objective-C interface. And, I gave you a pointer to the Apple documentation that describes the AppKit documentation.

I think you did misunderstand the forum description, but I'm not an authority on it.

As for your question specifically, I was able to find some guidance from the stackoverflow question “Show a GIF image using NSImageView”, where I learned that NSImageView has an animates property. Then I consulted the documentation for that animates property and found this:

Decoding an animated GIF file is the only way to create an animated NSImage object.

...which means there is no precise NSImageView equivalent of the UIImageView API you referenced. Perhaps you can combine your images into a GIF ahead of time.

Another approach would be to use a CAKeyframeAnimation on a CALayer's content to show your animation frames. I believe this is what UIImageView does under the hood. On macOS, you can set a CALayer's content to either a CGImage or an NSImage. But you'll need to create the layer yourself, as the documentation advises you not to change the content of a layer owned by an NSView.

1 Like

FYI..... the answer is SPRITEKIT

Terms of Service

Privacy Policy

Cookie Policy