gpt4 book ai didi

objective-c - iOS 中的动画背景

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:49:34 24 4
gpt4 key购买 nike

我想在我的 iOS 应用程序中加载 View 后为我的背景制作动画。这适用于纯色,但我无法让它使用背景图像。这是我的代码:

- (void)viewDidLoad
{
[super viewDidLoad];

[UIView animateWithDuration:5.0 animations:^{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]];
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background_dark.png"]];
}];

[UIView commitAnimations];
}

有谁知道正确的做法吗?

谢谢

最佳答案

你做这样的动画:

view.backgroundColor = INITIAL COLOR
[UIView animateWithDuration:5.0 animations:^{
view.backgroundColor = FINAL COLOR
}];

animate 方法动画化从当前状态到您在动画 block 中设置的任何状态的变化。动画 block 不是步骤列表。

因此,我认为你想要的是这样的:

self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]];
[UIView animateWithDuration:5.0 animations:^{
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background_dark.png"]];
}];

此外,不要在之后调用 commitAnimations,只有在您使用旧式 beginAnimations 方法时才会这样。阅读文档,不要只是调用方法来查看它们是否有效。

关于objective-c - iOS 中的动画背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8735194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com