1

我正在尝试为 my 设置动画UIImageView,使其从高度 x 到高度 y 进行动画处理,并且我有以下代码:

- (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;
}

但是,我在这里什么也没看到。我错过了什么?

4

1 回答 1

1

您似乎没有将其添加UIImageView到视图控制器的视图中。

前任

[self.view addSubview:test];
于 2011-09-04T23:18:31.470 回答