gpt4 book ai didi

objective-c - 将背景内容淡入新背景

转载 作者:行者123 更新时间:2023-11-28 13:14:24 27 4
gpt4 key购买 nike

我希望能够将我的背景从图像 bg1 淡化为 bg2

现在我正在尝试通过...对其进行动画处理

scene.background.contents = @"bg1";
[CATransaction begin];
CABasicAnimation *displayBackground2 =
[CABasicAnimation animation];
displayBackground2.keyPath = @"contents";
displayBackground2.toValue = @"bg2";
displayBackground2.duration = 5.0;
[scene.background addAnimation:displayBackground2
forKey:@"contents"];
[CATransaction commit];

但是我得到这个错误...

[SCNKit ERROR] contents is not an animatable path (from <SCNMaterialProperty: 0x170149530 | contents=bg1>)

Apple 的 API 中说 scene.background.contents,但我不知道如何为它设置动画。

最佳答案

如果您想使用 UIImageView 解决方案,这里有一个答案。

设置bg1bg2的图片:

//Declare them in header file

CGFloat imageHeight = self.height
CGFloat proportionalWidth = (height of background image / imageHeight) * self.width

//Set height and width to value of height and width of screen respectively

self.bg1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageHeight, proportionalWidth)];
[self.bg1 setImage:[UIImage imageNamed:@"the image"]];;
[self.view addSubview:self.bg1];

改变不透明度:

[UIView animateWithDuration: duration
animations: ^{[self.bg1 setAlpha: 0]}
];

从那里开始非常简单。要在延迟时间调用方法,请使用:

[self performSelector:@selector(methodName) withObject:nil afterDelay:delay];

关于objective-c - 将背景内容淡入新背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29682906/

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