问题描述
我正在尝试在我的应用中实现一个可隐藏的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!