作者:唐进水566673 | 来源:互联网 | 2022-12-10 13:21
我知道听起来这个问题有一个简单的答案,但是听我说.虽然UIStatusBar
是子类UIView
,但您不能使用该addSubview
方法向其添加子视图,因为它不使用它.同样的道理UIStatusBarWindow
.视图或窗口都没有viewcontroller,所以我无法以任何方式挂钩.
这是相关的代码部分.我在自己上调用addSubviews
方法的行是问题,因为addSubviews
它不是一种方法UIStatusBar
.
#import
@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
视图也会被隐藏.每当状态栏被隐藏时我都可以隐藏它,但是由于不同的应用程序使用了许多不同的隐藏状态栏的方法,这些方法并不像我希望的那样有效.