2010-01-06 51 views
0

這'我的代碼,我試圖改變我的imageView的大小。如果你能指出任何錯誤,我會非常感激..爲什麼我的CAKeyframeAnimation沒有得到執行?

UIImageView *imageViewForAnimation = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ravan.jpg"]]; 
    imageViewForAnimation.alpha = 1.0f; 
    CGSize size1=CGSizeMake(60,60); 
    CGSize size2=CGSizeMake(40,40); 
    CGSize size3=CGSizeMake(20,20); 
    CAKeyframeAnimation *customFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"frame"]; 
    NSArray *sizeValues = [NSArray arrayWithObjects:[NSValue valueWithCGSize:size1], [NSValue valueWithCGSize:size2], [NSValue valueWithCGSize:size3], nil]; 
    [customFrameAnimation setValues:sizeValues]; 
    customFrameAnimation.duration=10.0; 
    NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.5f], [NSNumber numberWithFloat:1.0f], nil]; 
    [customFrameAnimation setKeyTimes:times]; 
    customFrameAnimation.fillMode = kCAFillModeForwards; 
    customFrameAnimation.removedOnCompletion = NO; 
    [imageViewForAnimation.layer addAnimation:customFrameAnimation forKey:@"customFrameAnimation"]; 
    [self.view addSubview:imageViewForAnimation]; 

回答

3

你正在創建一個UIImageView,動畫連接到它,然後它泄漏。你永遠不會將它附加到可見的視圖。你甚至不應該在屏幕上看到這個imageview,更不用說動畫了。

如果要爲現有視圖設置動畫,則需要將動畫附加到該視圖上,而不是創建新視圖。

+0

Rob,我可以看到我的imageView位於左上角,但沒有使用動畫。動畫之後,我將這個視圖添加到自己。 – neha 2010-01-07 05:46:33

+0

我看你是編輯;你仍然在泄漏視圖。這就是說,上面的第一個問題是,你正在用CGSize動畫CGRect屬性(框架)。我很驚訝你在運行日誌中沒有收到某種警告,但無論如何,如果你想爲框架設置動畫,你需要傳遞CGRects而不是CGSizes。 – 2010-01-07 14:15:56

+0

Rob,frame是一個派生屬性,所以如果你想改變與它相關的任何東西,比如說。爲了改變大小,你必須提供valueWithCGSize,就像我在這裏完成的方式,或者如果你想改變位置,你必須提供valueWithCGPoint等。 – neha 2010-01-08 05:37:10

相關問題