热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

如何解决《如何在Theos中向UIStatusBar添加子视图?》经验,请问有什么解决方案?

我知道听起来这个问题有一个简单的答案,但是听我说.虽然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视图也会被隐藏.每当状态栏被隐藏时我都可以隐藏它,但是由于不同的应用程序使用了许多不同的隐藏状态栏的方法,这些方法并不像我希望的那样有效.


推荐阅读
author-avatar
唐进水566673
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有