在RootViewController设置安全区域safeAreaInsets,有关这个可以查资料了解下
// 适配iPhone X系列,设置安全区域
- (void)viewSafeAreaInsetsDidChange {
[super viewSafeAreaInsetsDidChange];
NSLog(@"viewSafeAreaInsetsDidChange %@",NSStringFromUIEdgeInsets(self.view.safeAreaInsets));
[self updateOrientation];
}
bool changeViewFrame = false;
- (void)updateOrientation {
if (@available(iOS 11.0, *)) {
if (IPHONE_X) {
if (self.view and !changeViewFrame) {
// CGRect s = CGRectMake(self.view.safeAreaInsets.left, Bottom_Safe_Height, self.view.frame.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right,
// self.view.frame.size.height - self.view.safeAreaInsets.bottom -self.view.safeAreaInsets.top/2);
CGRect s = CGRectMake(self.view.safeAreaInsets.left, Status_Height, kScreenWidth - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right,
kScreenHeight - self.view.safeAreaInsets.bottom -self.view.safeAreaInsets.top);
self.view.frame = s;
// 只需要记录一次,因为每次change view frame 都会改变一次这个
changeViewFrame = true;
}
}
}
}
设置完这里如果碰到输入框还是有问题,要修改:CCEAGLView-ios.mm
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)sampling numberOfSamples:(unsigned int)nSamples;
{
if((self = [super initWithFrame:frame]))
{
isUseUITextField = YES;
pixelformat_ = format;
depthFormat_ = depth;
multiSampling_ = sampling;
requestedSamples_ = nSamples;
preserveBackbuffer_ = retained;
markedText_ = nil;
if( ! [self setupSurfaceWithSharegroup:sharegroup] ) {
[self release];
return nil;
}
originalRect_ = self.frame;
self.keyboardShowNotification = nil;
if ([self respondsToSelector:@selector(setContentScaleFactor:)])
{
self.contentScaleFactor = [[UIScreen mainScreen] scale];
}
}
return self;
}
改后:
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)sampling numberOfSamples:(unsigned int)nSamples;
{
if (@available(iOS 11.0, *)) {
if ([[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0) {
CGSize screenSize = ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size);
frame = CGRectMake(0, 44, screenSize.width, screenSize.height - 44 - 34); // 上面44
}
}
if((self = [super initWithFrame:frame]))
{
isUseUITextField = YES;
pixelformat_ = format;
depthFormat_ = depth;
multiSampling_ = sampling;
requestedSamples_ = nSamples;
preserveBackbuffer_ = retained;
markedText_ = nil;
if( ! [self setupSurfaceWithSharegroup:sharegroup] ) {
[self release];
return nil;
}
originalRect_ = self.frame;
self.keyboardShowNotification = nil;
if ([self respondsToSelector:@selector(setContentScaleFactor:)])
{
self.contentScaleFactor = [[UIScreen mainScreen] scale];
}
}
return self;
}
亲测ok~~~
网友评论