如何让一个 UIView 总是出现在最前面? [英] How to make a UIView always appear at the front?

查看:17
本文介绍了如何让一个 UIView 总是出现在最前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个包含一些控件的 UIView.然后我将一些图像以编程方式添加到视图中以显示为动画.目前在我的游戏循环的每个间隔结束时,我必须告诉控制器将 UIView 控件移到前面,否则图像将出现在它的顶部.有没有一种成本更低的方法让它始终保持在最前面.

Currently I have a UIView which contains some controls. I then have some images I programatically add to the view to display as animations. Currently at the end of each interval of my game loop im having to tell the controller to move the UIView control to the front, otherwise the images will appear on top of it. Is there a less costly method of making it persist as always on top.

目前我在游戏循环结束时有以下内容:

[self.view bringSubviewToFront:myControlView];

我可以在游戏开始时做这样的事情吗:

myControlView.alwaysOnTop = true;

推荐答案

与其使用 -addSubview: 插入图片,不如使用 -insertSubview:belowSubview: 并通过你的 UIView 作为第二个参数:

Rather than using -addSubview: to insert your images, use -insertSubview:belowSubview: and pass your UIView as the second parameter:

[self.view insertSubview:myImage belowSubview:myControlView];

请注意,出于类似目的,您还可以访问方法 -insertSubview:aboveSubview:-insertSubview:atIndex:.

Note that for similar purposes you also have access to the methods -insertSubview:aboveSubview: and -insertSubview:atIndex:.

这篇关于如何让一个 UIView 总是出现在最前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆