簡體   English   中英

如何強制UIButton始終位於頂部

[英]How to force a UIButton to always be on top

我有一個UIButton和一個UIView動畫,按下UIButton時向下滑動。 問題是UIView掩蓋了UIButton 我希望UIButton始終保持領先UIButton

我在viewDidLoad試過這個:

    [self.view bringSubviewToFront:categoryBtn];

雖然不起作用。

謝謝你的幫助

在此主視圖上添加任何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];
}

另一個答案是可行的,但這正是添加“insertSubview:belowSubview”的事情。

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

這允許您在視圖堆棧上的按鈕下添加新視圖,而不是將其添加到按鈕上方,然后重新排列視圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM