2013-01-02 69 views
-2

我不知道如何製作動畫,或者我會如何將它放入Xcode。有人可以給我一些關於這方面的背景資料嗎?如何將動畫添加到Xcode中?

+0

http://stackoverflow.com.tw m/questions/630265/iphone-uiview-animation-best-practice –

+0

嘗試使用Google。 「Xcode動畫」。有很多關於它的信息。 –

+0

http://www.apeth.com/iOSBook/ch17.html – matt

回答

5
NSArray *animationArray = [NSArray arrayWithObjects:[UIImage [email protected]"firstImage",[UIImage [email protected]"secondImage",nil]; //add as many as you want 

現在你需要一個imageview的設置動畫:

self.myImageView.animationImages =animationArray; 
self.myImageView.animationDuration = 3; 
self.myImageView.animationRepeatCount = -1; //keeps going infinitely 

[self.myImageView startAnimating]; 
0

我猜你想要做的是創建一個動畫圖像,而不是動畫化一個視圖過渡...這裏有兩個創建iOS動畫的方法背景。

第一個選項:創建圖像數組(UIImage),然後使用startAnimating方法。 事情是這樣的:

imageView.image = yourLastImage; 
// Do this first so that after the animation is complete the image view till show your last image. 

NSArray * imageArray = [[NSArray alloc] initWithObjects: 
[UIImage imageNamed:@"image1.png"], 
[UIImage imageNamed:@"image2.png"], 
[UIImage imageNamed:@"image3.png"],       
[UIImage imageNamed:@"image4.png"], 
nil]; 

// Note: here you may instead want to use something like [UIImage imageWithContentsOfFile:[self localImagePath:NO]] instead depending upon your targeted iOS version. 



UIImageView * animatedImageView = [[UIImageView alloc] initWithFrame: 
     CGRectMake(100, 125, 150, 130)]; 
    animatedImageView.animationImages = imageArray; 
    animatedImageView.animationDuration = 1.1; 
     myAnimation.animationRepeatCount = 1; 
    animatedImageView.contentMode = UIViewContentModeBottomLeft; 

    [self.view addSubview:animatedImageView]; 
    [animatedImageView startAnimating]; 

第二個選項:(適用於iOS 4及更高版本)可以使用基於塊的方法。這裏是一個指向StackOverflow的參考文章的鏈接。

What are block-based animation methods in iPhone OS 4.0?

你也可能想看看,蘋果提供與核心動畫文件:

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/AnimatingLayers.html#//apple_ref/doc/uid/TP40006085-SW1