簡體   English   中英

動畫UIImageView

[英]Animating a UIImageView

我正在嘗試為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;
}

但是,我在這里看不到任何東西。 我想念什么?

您似乎沒有將UIImageView添加到視圖控制器的視圖中。

[self.view addSubview:test];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM