UIView 总是顶部子视图 [英] UIView always top subview

查看:33
本文介绍了UIView 总是顶部子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个游戏,我在其中创建了一个处理触摸事件的子视图.但是当我稍后在代码中添加其他对象时,它们会出现在该视图的前面.因此,如果用户在这些对象之一上点击屏幕,则不会注册触摸.那么有没有办法让 UIView 总是出现在顶部呢?我试过这个,但它不起作用:view.layer.zPosition = MAXFLOAT;

Hi I have a game where I create a subview that handles touch events. But when I add other objects later in the code, they appear in front of that view. So if the user tap the screen on one of these objects the touch won't be registered. So is there a way to make a UIView always appear on the top? I have tried this, but it doesn't work: view.layer.zPosition = MAXFLOAT;

有什么想法吗?谢谢

推荐答案

尝试使用 bringSubviewToFront:,对我有用:

Try with bringSubviewToFront:, did the trick for me:

[[self view] bringSubviewToFront:yourView];

这篇关于UIView 总是顶部子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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