iPhoneX,也就是刘海屏的情况下 foregroundView报错
[ valueForUndefinedKey:]:thisclassis not key value coding-compliantforthe key foregroundView.
解决方法:
NSArray*subviews =nil;// 不能用 [[self deviceVersion] isEqualToString:@"iPhone X"] 来判断,因为模拟器不会返回 iPhone X
id statusBar = [[UIApplicationsharedApplication] valueForKeyPath:@"statusBar"];
if([statusBar isKindOfClass:NSClassFromString(@"UIStatusBar_Modern")]) {
subviews = [[[statusBar valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
}else{
subviews = [[statusBar valueForKey:@"foregroundView"] subviews];
}
网友评论