【问题标题】:How to force a UIButton to always be on top如何强制 UIButton 始终位于顶部
【发布时间】:2013-01-07 12:31:37
【问题描述】:

我有一个 UIButton 和一个 UIView 动画,当按下 UIButton 时向下滑动。问题是UIView 掩盖了UIButton。我希望UIButton 始终保持领先。

我在viewDidLoad中试过这个:

    [self.view bringSubviewToFront:categoryBtn];

虽然没有用。

感谢您的帮助

【问题讨论】:

  • 是你的按钮父视图是self.view

标签: iphone objective-c ios uiview uibutton


【解决方案1】:

在此主视图上添加任何 UIView 或任何其他视图之后,只需将您的这一行添加为按钮的超级视图

[self.view bringSubviewToFront:categoryBtn];

例如,在按钮操作事件上,您可以添加任何视图,然后使用如下代码..

-(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];
}

【讨论】:

  • 将 UIButton 添加到应用程序窗口本身会有帮助吗?这样做有什么坏处?
【解决方案2】:

另一个答案是可行的,但这正是添加“insertSubview:belowSubview”的那种东西。

[self.view insertSubview:myNewView belowSubview:_categoryBtn];

这允许您在视图堆栈上的按钮下方添加新视图,而不是将其添加到按钮上方然后重新排列视图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    相关资源
    最近更新 更多