我知道这个问题似乎有一个简单的答案,但请听我说完。虽然
以下是相关的代码片段。我在self上调用
UIStatusBar
是UIView
的子类,但您不能使用addSubview
方法将子视图添加到它,因为它不使用它。同样适用于UIStatusBarWindow
。视图和窗口都没有视图控制器,所以我无法以任何方式连接到它。以下是相关的代码片段。我在self上调用
addSubviews
方法的那一行是问题所在,因为addSubviews
不是UIStatusBar
的方法。#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
视图也会被隐藏。我可以在状态栏隐藏时隐藏它,但由于不同的应用程序使用许多不同的方法来隐藏状态栏,这并不像我希望的那样有效。