2015-10-21 106 views
0

我正在生成一串框架,我想在Apple Watch上進行動畫處理。以編程方式創建框架的UIImage動畫

根據的信息,我已經在互聯網上發現,每個人似乎都使用imageWithName動畫一個UIImage,如下面的SO職位:Is it possible to animate an UIImage?

第一個答案建議下面的代碼,它使用UIImageView

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

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

但是,當我嘗試將它添加到我的Apple Watch代碼中時,UIImageView在Swift中似乎不存在於XCode 7中? 爲什麼?


我也嘗試下面的代碼,我寫我自己:

... 

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

... 

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

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

最後一行給了我這說的錯誤:

無法指定屬性: 'images'是一個只可訪問的屬性

回答

1

您應該使用

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

要創建動畫UIImage

var animation = UIImage.animatedImageWithImages(images: frames, duration: NSTimeInterval) 
+0

完美!!!!!!!!! – vaid