0

I am generating a bunch of frames which I want to animate on my Apple Watch.

According to info I've found on the internet, everyone seems to be using imageWithName to animate a UIImage, such as the following SO post: Is it possible to animate an UIImage?

The first answer suggest the following code which uses UIImageView:

NSArray *animationFrames = [NSArray arrayWithObjects:
  [UIImage imageWithName:@"image1.png"],
  [UIImage imageWithName:@"image2.png"], 
  nil];

UIImageView *animatedImageView = [[UIImageView alloc] init];
animatedImageView.animationImages = animationsFrame;
[animatedImageView startAnimating];

However `UIImageView does not seem to exist in XCode 7 with Swift when I try to add it to my Apple Watch code? Why?


I also try the following code which I wrote myself:

...

var frames = [UIImage]()
var animation = UIImage()

...

//1. generate frame
//2. add to array "frames"

animation.images = frames //apply frame array to main animatable UIImage.

The last line gives me an error which says:

Cannot assign to property: 'images'is a get-only property

Community
  • 1
  • 1
vaid
  • 1,390
  • 12
  • 33

1 Answers1

1

You should use

    UIImage.animatedImageWithImages(images: [UIImage], duration: NSTimeInterval)

To create your animating UIImage

i.e.

var animation = UIImage.animatedImageWithImages(images: frames, duration: NSTimeInterval)
Moriya
  • 7,750
  • 3
  • 35
  • 53