强制 UIImageView 保持在活动动画的前面
Forcing a UIImageView to Remain in Front of an Active Animation
语言:Swift,IDE:Xcode 用于 iOS 开发,单视图应用程序 > 视图控制器...
我有 2 个 UI 图像视图,它们具有相同的图像,我在视图中从左到右滚动动画,以创建某种 'slowly-moving background'。我想在这个重复的背景动画的前景中放置其他 UI 元素(标签、其他图像等),但是发现当我 运行 模拟器时看不到前景图像。 ..
问题:是否可以通过编程强制其他 UI 元素停留在重复动画的前面?
我不在 Mac,所以我现在不能分享我的代码,但是如果你知道 and/or 这个问题的直接答案,哪种方法可以最好地实现这一点,我洗耳恭听!!
提前致谢! :)
这取决于视图的 z 顺序。假设您要添加所有视图然后开始动画调用 bringSubViewToFront on the view you are animating right before you start animating it. If you are laying things out in interface builder the Z order is based on top = farthest and bottom = closest. If you are adding view programmatically the newest view is always added in front. You can change this with insertSubview:at: and the related methods. Take a look at the documentation for UIView。
如果你想要 z-index 使用:
YourImageViewName.layer.zPosition = 1
您也可以在父视图上使用 bringToFront 方法:
self.view.bringSubviewToFront(YourImageViewName)
希望这能解决您的问题。
语言:Swift,IDE:Xcode 用于 iOS 开发,单视图应用程序 > 视图控制器...
我有 2 个 UI 图像视图,它们具有相同的图像,我在视图中从左到右滚动动画,以创建某种 'slowly-moving background'。我想在这个重复的背景动画的前景中放置其他 UI 元素(标签、其他图像等),但是发现当我 运行 模拟器时看不到前景图像。 ..
问题:是否可以通过编程强制其他 UI 元素停留在重复动画的前面?
我不在 Mac,所以我现在不能分享我的代码,但是如果你知道 and/or 这个问题的直接答案,哪种方法可以最好地实现这一点,我洗耳恭听!!
提前致谢! :)
这取决于视图的 z 顺序。假设您要添加所有视图然后开始动画调用 bringSubViewToFront on the view you are animating right before you start animating it. If you are laying things out in interface builder the Z order is based on top = farthest and bottom = closest. If you are adding view programmatically the newest view is always added in front. You can change this with insertSubview:at: and the related methods. Take a look at the documentation for UIView。
如果你想要 z-index 使用:
YourImageViewName.layer.zPosition = 1
您也可以在父视图上使用 bringToFront 方法:
self.view.bringSubviewToFront(YourImageViewName)
希望这能解决您的问题。