动画一个UIImageView

问题描述:

我想我的动画所以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; 
} 

不过,我不是在这里看到任何东西。我错过了什么?

它不会出现你添加UIImageView到你的视图控制器的视图。

e.x.

[self.view addSubview:test]; 
+0

它在IB创建,我已经连接的插座以及 – adit

+0

但你似乎重新分配出口(self.test),这将失去你曾与IB创建的UIImageView原来的连接。如果要缩放在IB中创建的图像视图,请将变换应用于self.test; theres不需要创建一个新的UIImageView。 – Sam