我知道这个问题听起来很简单,但请听我说完。尽管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视图也会被隐藏。我可以在状态栏被隐藏的时候隐藏它,但由于不同的应用程序使用了许多不同的方法来隐藏状态栏,结果并不像我希望的那样好。
https://stackoverflow.com/questions/51388988
复制相似问题