2011-06-15 14 views
3

以下代碼用於在使用iOS 3.x構建時工作。現在使用4.x不起作用。換句話說,我可以在同一個設備上運行兩個完全相同的應用程序,一個是針對每個4.x版本構建的,另一個是4.3,而後者是,動畫不會更改值,除非屏幕被輕敲或方向改變。UIImageView是否在4.0 SDK中動畫破解?

這裏是相關的代碼。我開始在Xcode中使用基於視圖的模板。

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    iv.animationImages = [NSArray arrayWithObjects: 
             [UIImage imageNamed:@"timer00.png"], 
             [UIImage imageNamed:@"timer01.png"], 
             [UIImage imageNamed:@"timer02.png"], 
             [UIImage imageNamed:@"timer03.png"], 
             [UIImage imageNamed:@"timer04.png"], 
             [UIImage imageNamed:@"timer05.png"], 
             [UIImage imageNamed:@"timer06.png"], 
             [UIImage imageNamed:@"timer07.png"], 
             [UIImage imageNamed:@"timer08.png"], 
             [UIImage imageNamed:@"timer09.png"], 
             [UIImage imageNamed:@"timer10.png"], 
             [UIImage imageNamed:@"timer11.png"], 
             [UIImage imageNamed:@"timer12.png"], 
             [UIImage imageNamed:@"timer13.png"], 
             [UIImage imageNamed:@"timer14.png"], 
             [UIImage imageNamed:@"timer15.png"], 
             [UIImage imageNamed:@"timer16.png"], 
             [UIImage imageNamed:@"timer17.png"], 
             [UIImage imageNamed:@"timer18.png"], 
             [UIImage imageNamed:@"timer19.png"], 
             [UIImage imageNamed:@"timer20.png"], 
             [UIImage imageNamed:@"timer21.png"], 
             [UIImage imageNamed:@"timer22.png"], 
             [UIImage imageNamed:@"timer23.png"], 
             [UIImage imageNamed:@"timer24.png"], 
             [UIImage imageNamed:@"timer25.png"], 
             [UIImage imageNamed:@"timer26.png"], 
             [UIImage imageNamed:@"timer27.png"], 
             [UIImage imageNamed:@"timer28.png"], 
             [UIImage imageNamed:@"timer29.png"], 
             [UIImage imageNamed:@"timer30.png"], 
             [UIImage imageNamed:@"timer31.png"], 
             [UIImage imageNamed:@"timer32.png"], 
             [UIImage imageNamed:@"timer33.png"], 
             [UIImage imageNamed:@"timer34.png"], 
             [UIImage imageNamed:@"timer35.png"], 
            [UIImage imageNamed:@"timer36.png"],          nil]; 
    iv.animationDuration = 5.0; 
    iv.animationRepeatCount = 1; 
    [iv startAnimating]; 
    timer = [NSTimer scheduledTimerWithTimeInterval:0.5 
              target:self 
              selector:@selector(periodicallyUpdateView) 
              userInfo:nil 
              repeats:YES]; 
} 

- (void)periodicallyUpdateView { 
    if ([iv isAnimating]) { 
     NSLog(@"it is animating"); 
    } 
    else { 
     NSLog(@"it is NOT animating"); 
    } 
} 

其他人看到了嗎?

+0

與問題無關,但遺憾的是,這是一個非常糟糕的代碼。你應該使用循環來創建數組。 – taskinoor 2011-06-15 08:40:11

+0

我不想搞亂Mutable數組。或者你有另一種方式來做到這一點? – mahboudz 2011-06-15 09:46:32

+0

我比較喜歡可變數組。儘管它是個人選擇。 – taskinoor 2011-06-15 10:07:07

回答

1

如果你設置一個計時器,這將會更有效率。您遇到的問題可能不是UIImageView被破壞,而是圖像視圖花費很長時間來加載動畫。

我推薦這樣的東西。

NSTimer *imageTimer; 

int animationCount; 

- (void)startAnimation 
{ 
     imageTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(switchImage) userInfo:nil repeats:YES]; 
} 

- (void)switchImage 
{ 
     NSString *imageName = [NSString stringWithFormat:@"timer%i" , animationCount]; 
     UIImage *image = [UIImage imageNamed:imageName]; 
     someImageView.image = image; 
}