动画 UIImageView

发布于 2024-12-03 02:06:01 字数 1067 浏览 4 评论 0原文

我正在尝试对我的 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;
}

但是,我在这里没有看到任何内容。我缺少什么?

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)];
   }

- (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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薔薇婲 2024-12-10 02:06:01

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

前任

[self.view addSubview:test];

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

e.x.

[self.view addSubview:test];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文