为什么我无法向 UIImageView 添加动画?

发布于 2024-08-27 08:36:04 字数 742 浏览 13 评论 0原文

我尝试向 UIImageView 添加动画,但总是失败。为什么?这是代码:

        //(…)
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
        animationImage = [[UIImageView alloc]initWithImage:newImage];
        [self.view addSubview:animationImage];

        CATransition *animation = [CATransition animation];
        [animation setDelegate:self];
        [animation setDuration:0.35];
        [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
        animation.type = @"pageCurl";
        animation.fillMode = kCAFillModeForwards;
        animation.endProgress = 0.58;
        [animation setRemovedOnCompletion:NO];
        [[animationImage layer] addAnimation:animation forKey:@"pageCurlAnimation"];

Im trying to add a animation to a UIImageView, but it always fails. Why? Here is the code:

        //(…)
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
        animationImage = [[UIImageView alloc]initWithImage:newImage];
        [self.view addSubview:animationImage];

        CATransition *animation = [CATransition animation];
        [animation setDelegate:self];
        [animation setDuration:0.35];
        [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
        animation.type = @"pageCurl";
        animation.fillMode = kCAFillModeForwards;
        animation.endProgress = 0.58;
        [animation setRemovedOnCompletion:NO];
        [[animationImage layer] addAnimation:animation forKey:@"pageCurlAnimation"];

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

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

发布评论

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

评论(1

枉心 2024-09-03 08:36:04

尝试使用:

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

代替:

[animation setTimingFunction:UIViewAnimationCurveEaseInOut];

Try using:

[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

insteaad of:

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