将UIButton作为子视图添加到UITabBar

我正试图在我的应用程序中实现一个隐藏的UITabBar。 我制作了所有的animation,效果非常好。 我只是有一个问题,让我的UIButton“拉标签”显示标签栏。 它不响应触摸事件UIControlEventTouchUpInside。 我把这个pull标签添加到UITabBarController的UITabBar中:

- (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]; } 

这是标签栏看起来像打开和closures的内容:

TabBar不隐藏TabBar隐藏

编辑:我已经确定,问题是因为button不在UITabBar的框架。 看起来我将不得不把button放在UITabBar之外…animation噩梦。

你仍然可以将UIButton添加到UITabBarController的主视图,而不是在UITabBar但是…. [myUITabBarController.view addSubview:pullButton]

既然你有UITabbar中的隐藏部分和我在这里看到的答案,另一种方法是将UIButton保留在UITabbar中,而且在隐藏UITabbar时将button添加到视图(所以你将有两个button覆盖)。 当显示标签栏时, 隐藏使用视图上的隐藏属性添加到视图中的button。