2011-09-04 192 views
1

我想我的動畫所以UIImageView它從高度動畫x到高度y和我有以下代碼:動畫一個UIImageView

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.test = [self createNewBarWithValue:800 atLocation:CGPointMake(107, 43)]; 
    } 

- (UIImageView*)createNewBarWithValue:(float)percent atLocation:(CGPoint)location 
{ 
    UIImageView *newBar = [[[UIImageView alloc] initWithFrame:CGRectMake(location.x, location.y, 107, 43)] autorelease]; 
    newBar.image = [UIImage imageNamed:@"bar.png"]; 

    CABasicAnimation *scaleToValue = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"]; 
    scaleToValue.toValue = [NSNumber numberWithFloat:percent]; 
    scaleToValue.fromValue = [NSNumber numberWithFloat:0]; 
    scaleToValue.duration = 1.0f; 
    scaleToValue.delegate = self; 

    newBar.layer.anchorPoint = CGPointMake(0.5, 1); 

    [newBar.layer addAnimation:scaleToValue forKey:@"scaleUp"]; 
    CGAffineTransform scaleTo = CGAffineTransformMakeScale(1.0f, percent); 
    newBar.transform = scaleTo; 

    return newBar; 
} 

不過,我不是在這裏看到任何東西。我錯過了什麼?

回答

1

它不會出現你添加UIImageView到你的視圖控制器的視圖。

e.x.

[self.view addSubview:test]; 
+0

它在IB創建,我已經連接的插座以及 – adit

+0

但你似乎重新分配出口(self.test),這將失去你曾與IB創建的UIImageView原來的連接。如果要縮放在IB中創建的圖像視圖,請將變換應用於self.test; theres不需要創建一個新的UIImageView。 – Sam