在我的应用程序中,存在一种情况,我通过[self.tabBarController.tabBar setHidden:YES]隐藏底部TabBar,然后在视图底部的空出区域添加包含UIButtons的UIView。
TabBar所在的区域不会响应触摸事件,因此我无法选择UIView中的任何按钮。
我已经在这里做过研究,这个问题已经存在了一段时间,但旧答案似乎不再起作用了。 [self setNeeds Display]
和self.tabBarController.tabBar.translucent = YES
不再工作,因为您仍然无法按下UIButtons。在旁注中,我在故事板中使用UIButtons创建了我的UIView,并为superview设置了一个底部约束。请提供适用于iOS 9和10的已知答案。
答案 0 :(得分:0)
我根据问题创建了一个项目。它工作正常。请试试这个。
- (void)viewDidLoad {
[super viewDidLoad];
[self.tabBarController.tabBar setHidden:YES];
UIView *view = [[UIView alloc]initWithFrame:self.tabBarController.tabBar.frame];
[self.view addSubview:view];
view.backgroundColor = [UIColor redColor];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100,view.frame.size.height)];
[view addSubview:btn];
[btn setTitle:@"clicked me " forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnclicked:) forControlEvents:UIControlEventTouchDown];
}
-(void)btnclicked:(UIButton *)sender{ NSLog(@"button clicked event."); }
答案 1 :(得分:-1)
我创建了一个测试项目来检查你想要的功能。
类ViewController:UIViewController {
@IBOutlet weak var testButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
testButton.addTarget(self, action: #selector(tapped), for: .touchUpInside)
self.tabBarController?.tabBar.isHidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tapped(_ sender:UIButton){
print("Tapped")
}
}
根据您的要求,我创建了一个包含UIButton作为子视图的uiview,并为按钮创建了一个插座。 因为,我在按钮上按下按钮,触发了动作。