我在UITabBarViewController添加定製中心按鈕,如下面的代碼沒有隱瞞......的UITabBarController自定義按鈕,同時移動到下一個視圖控制器
self.centerButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.centerButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
self.centerButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[self.centerButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[self.centerButton setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
CGFloat heightDifference = buttonImage.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0) {
self.centerButton.center = self.tabBar.center;
} else {
CGPoint center = self.tabBar.center;
center.y = center.y - heightDifference/2.0;
self.centerButton.center = center;
}
[self.centerButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.centerButton];
請檢查連接參考截圖,
現在,當我試圖隱藏它而移動到其他viewcontroller時,只有tabbar被隱藏,而不是與下面的代碼中心自定義按鈕,
[self.tabBarController.tabBar setHidden:YES];
也試過像這樣隱藏中心的自定義按鈕,
WBTabBarController *objWBTab = [self.storyboard instantiateViewControllerWithIdentifier:ID_CNTRL_TABBAR];
[objWBTab setTabBarHidden:YES];
SetTabBarHidden已WBTabBarController.m被定義爲以下,
- (void)setTabBarHidden:(BOOL)tabBarHidden
{
self.centerButton.hidden = tabBarHidden;
self.tabBar.hidden = tabBarHidden;
}
仍然沒有運氣,任何人可以幫助我嗎?
你爲什麼不只是添加'UIButton'作爲標籤欄的子視圖而不是'self.view'? – Rikh
由於自定義按鈕的高度較大,所以我必須添加它在self.view,我不能將它添加到標籤欄 – Gati
嗯不設置剪輯界限爲false的tabbar做同樣的事情?像按鈕可以在標籤欄的邊界外可見 – Rikh