问题描述
我正在尝试在我的应用中实现可隐藏的UITabBar。我已经设置了所有的动画,并且它们运行得非常好。我只是遇到一个问题,让我的UIButton拉片显示标签栏。它没有响应触摸事件UIControlEventTouchUpInside。
我将拉标签添加到UITabBarController中的UITabBar:
I am trying to implement a hideable UITabBar in my app. I've set up all the animations, and they work very well. I'm just having an issue getting my UIButton "pull-tab" to show the tab bar. It is not responding to the touch event UIControlEventTouchUpInside.I add the pull-tab to the UITabBar in the UITabBarController:
- (void)viewDidLoad
{
[super viewDidLoad];
//Add pull
pullButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [UIImage imageNamed:@"TabBarPull.png"];
pullButton.frame = CGRectMake(self.tabBar.frame.size.width - image.size.width, -image.size.height + 3, image.size.width, image.size.height);
[pullButton setImage:image forState:UIControlStateNormal];
[pullButton addTarget:self action:@selector(pullBarTapped:) forControlEvents:UIControlEventTouchUpInside];
pullButton.userInteractionEnabled = YES;
[self.tabBar addSubview:pullButton];
}
以下是标签栏的打开和关闭状态:
Here is what the tab bar looks like open and closed:
编辑:我已确定问题是因为按钮落在UITabBar的框架之外。看起来我将不得不把按钮放在UITabBar ...动画噩梦之外。
I've determined that the problem is because the button falls outside the UITabBar's frame. Looks like I'm going to have to put the button outside of the UITabBar... Animation nightmare.
推荐答案
你仍然可以将 UIButton
添加到 UITabBarController
的主视图中,而不是 UITabBar
虽然.... [myUITabBarController.view addSubview:pullButton]
You can still add the UIButton
to the UITabBarController
's main view, not in the UITabBar
though.... [myUITabBarController.view addSubview:pullButton]
这篇关于将UIButton作为子视图添加到UITabBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!