我正在尝试在我的应用程序中实现一个可隐藏的 UITabBar。我已经设置了所有的动画,它们工作得很好。我只是在让我的 UIButton“拉动标签”显示标签栏时遇到问题。它不响应触摸事件 UIControlEventTouchUpInside。 我将拉环添加到 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];
}
这是标签栏打开和关闭时的样子:
编辑:我确定问题是因为按钮落在 UITabBar 的框架之外。看来我不得不将按钮放在 UITabBar 之外……动画噩梦。
最佳答案
您仍然可以将 UIButton
添加到 UITabBarController
的主视图中,而不是在 UITabBar
中...... [myUITabBarController.view addSubview:pullButton]
关于ios - 将 UIButton 作为 subview 添加到 UITabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11588752/