簡體   English   中英

如何在iOS SDK中隱藏標簽欄時如何向UITabBar添加中心按鈕並將其隱藏?

[英]How to add center button to UITabBar and hide it when tab bar is hidden in iOS SDK?

我正在自定義標簽欄上。 我使用以下代碼在選項卡欄的中間添加了按鈕:

button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0,0,50,50);
[button setBackgroundImage:[UIImage imageNamed:@"uploader_disabled.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"uploader_enabled.png"] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(OpenActionSheet) forControlEvents:UIControlEventTouchUpInside];
CGFloat heightDifference = button.frame.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0)
{
    button.center = self.tabBar.center;
    NSLog(@"heightDifference");
}
else
{
    NSLog(@"not heightDifference");

    CGPoint center = self.tabBar.center;
    center.y = center.y - heightDifference/2.0;
    button.center = center;
}

[self.view addSubview:button];

現在,當我隱藏標簽欄時,此按鈕不會被隱藏。 在所有視圖控制器中均可見。

感謝您在解決此問題方面的幫助。

您將在self.view上添加按鈕。 您應該在tabbar對其進行廣告。

[self.tabBar addSubview:button];

您可以像這樣添加。向按鈕欄控件添加按鈕,如下所示。隱藏Uitabbar之后[myTabBarController.view addSubview:myButton];

暫無
暫無

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

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