ios - 将 UIButton 作为 subview 添加到 UITabBar

标签 ios uiview uibutton uitabbarcontroller uitabbar

我正在尝试在我的应用程序中实现一个可隐藏的 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];
}

这是标签栏打开和关闭时的样子:

TabBar not hidden TabBar Hidden

编辑:我确定问题是因为按钮落在 UITabBar 的框架之外。看来我不得不将按钮放在 UITabBar 之外……动画噩梦。

最佳答案

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

关于ios - 将 UIButton 作为 subview 添加到 UITabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11588752/

相关文章:

iOS - 单例 UIView? Facebook 风格的导航

ios - 如何让文本适合 UIButton?

ios - UICollectionVIew:滚动时动画单元格

android - 使用 Cordova 的 Azure 通知中心

iphone - convertRect 获取父 View 中的相对位置

iOS View.layer.border 有白边

ios - 按钮高度无法调整

ios - 如何禁用 UIButton 的高亮控件状态?

c# - 添加 UITabBarController 时出错

ios - 了解 Swift 映射语法