开发者

Animating a UIImageView

开发者 https://www.devze.com 2023-04-02 15:55 出处:网络
I am trying to animate my UIImageView so that it animates from height x to height y and I have the following code:

I am trying to animate my UIImageView so that it animates from height x to height y and I have the following code:

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

开发者_JS百科- (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;
}

However, I am not seeing anything here. What am I missing?


It doesn't appear you add the UIImageView to your view controller's view.

e.x.

[self.view addSubview:test];
0

精彩评论

暂无评论...
验证码 换一张
取 消