[英]How to force a UIButton to always be on top
I have a UIButton
and a UIView
that animates, sliding down when the UIButton
is pressed. 我有一个
UIButton
和一个UIView
动画,按下UIButton
时向下滑动。 The problem is that the UIView
obscures the UIButton
. 问题是
UIView
掩盖了UIButton
。 I'd like the UIButton
to always remain on top. 我希望
UIButton
始终保持领先UIButton
。
I tried this in the viewDidLoad
: 我在
viewDidLoad
试过这个:
[self.view bringSubviewToFront:categoryBtn];
doesn't work though. 虽然不起作用。
thanks for any help 谢谢你的帮助
After Add any UIView
or any other view on your this mainview , after that just add your this line for brings as a supeview for button 在此主视图上添加任何
UIView
或任何其他视图后,只需添加此行以作为按钮的超级视图
[self.view bringSubviewToFront:categoryBtn];
For Example on button action event you add any view then use code like bellow.. 有关按钮操作事件的示例,您可以添加任何视图,然后使用类似下面的代码。
-(IBAction)yourButton_Clicked:(id)sender
{
///Add some code or view here and then after write this line here see bellow line
[self.view bringSubviewToFront:categoryBtn];
}
The other answer is will work, but this is exactly the kind of thing "insertSubview: belowSubview" was added for. 另一个答案是可行的,但这正是添加“insertSubview:belowSubview”的事情。
[self.view insertSubview:myNewView belowSubview:_categoryBtn];
This allows you to add the new view below the button on the view stack instead of adding it above the button and then rearranging the views. 这允许您在视图堆栈上的按钮下添加新视图,而不是将其添加到按钮上方,然后重新排列视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.