【发布时间】:2019-03-25 11:13:14
【问题描述】:
我想创建自定义导航栏,就像 WhatsApp 用来在应用程序中显示呼叫指示器一样,如下所示。
我已成功添加上述视图,但它没有响应,因为我无法检测到状态栏上的触摸。我只能触摸“触摸返回通话”下方的部分。
代码如下。
@property (nonatomic) UIView *navigationBarTopView;
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if (_navigationBarTopView == nil) {
_navigationBarTopView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, window.frame.size.width, 60.0)];
[_navigationBarTopView setBackgroundColor:[UIColor colorWithRed:76.0/255.0 green:217.0/255.0 blue:100.0/255.0 alpha:1]];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, _navigationBarTopView.frame.size.height - 15, window.frame.size.width, 10)];
[label setText:@"Touch to return to call"];
[label setTextColor:[UIColor whiteColor]];
[label setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]];
[label setTextAlignment:NSTextAlignmentCenter];
[_navigationBarTopView addSubview:label];
//The setup code (in viewDidLoad in your view controller)
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[_navigationBarTopView addGestureRecognizer:singleFingerTap];
UITapGestureRecognizer *singleFingerTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[label addGestureRecognizer:singleFingerTap1];
}
[window addSubview:_navigationBarTopView];
我也尝试在状态栏上添加触摸,如下所示,但它不起作用。
How do I detect touches on UIStatusBar/iPhone
导航栏也没有下降。我试图设置keyWindow 框架。但这也行不通。
【问题讨论】:
-
你确定这不是系统
call bar? -
试试这个
[self.navigationController.view addSubview: _navigationBarTopView]; -
是系统生成的导航栏。它会在与任何人通话时自动出现。通话可以是普通电话或VoIP(由SDK管理)。如果需要,您可以向导航栏添加自定义视图。
-
它是苹果提供的默认行为,如果您想创建相同的行为,例如将子视图添加到顶部视图控制器上的 navigationController.view
-
@iMHiteshSurani 我没有将它放入应用程序。我已经为此实现了 Twilio Voice SDK。所以我创建了自定义视图并将其添加为屏幕顶部的 UIWindow。
标签: ios uinavigationbar custom-view uistatusbar