如何使UIView始终出现在前面? [英] How to make a UIView always appear at the front?

查看:108
本文介绍了如何使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 as第二个参数:

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天全站免登陆