首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Theos中向UIStatusBar添加子视图?

如何在Theos中向UIStatusBar添加子视图?
EN

Stack Overflow用户
提问于 2018-07-18 03:34:11
回答 0查看 335关注 0票数 9

我知道这个问题听起来很简单,但请听我说完。尽管UIStatusBarUIView的子类,但不能使用addSubview方法向其添加子视图,因为它不使用子视图。UIStatusBarWindow也是如此。视图和窗口都没有视图控制器,所以我不能以任何方式连接到视图控制器。

以下是代码的相关部分。我在self上调用addSubviews方法的那一行才是问题所在,因为addSubviews不是UIStatusBar的方法。

代码语言:javascript
复制
#import <CoreGraphics/CoreGraphics.h>

@interface UIStatusBar : UIView
@end

%hook UIStatusBar
- (void)layoutSubviews {
  //Round corners under status bar
  CGFloat radius = 15;
  CGRect wholeScreen = [[UIScreen mainScreen] bounds];
  UIView *roundedCorners = [[UIView alloc] initWithFrame: CGRectMake(-radius, 20-radius, wholeScreen.size.width+2*radius, wholeScreen.size.height-20+2*radius)];
  roundedCorners.layer.borderWidth = radius;
  roundedCorners.layer.cornerRadius = 2*radius;
  roundedCorners.layer.borderColor = UIColor.blackColor.CGColor;
  roundedCorners.userInteractionEnabled = NO;
  [self addSubView:roundedCorners];
}
%end

有没有其他方法可以添加子视图?我尝试这样做的原因是,每当隐藏状态栏时,我的roundedCorners视图也会被隐藏。我可以在状态栏被隐藏的时候隐藏它,但由于不同的应用程序使用了许多不同的方法来隐藏状态栏,结果并不像我希望的那样好。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51388988

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档