在向上推送过程方向不对。
#pragma mark UIKeyboard notification - (void)onUIKeyboardNotification:(NSNotification *)notif; { NSString * type = notif.name; NSDictionary* info = [notif userInfo]; CGRect begin = [self convertRect: [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue] fromView:self]; CGRect end = [self convertRect: [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:self]; CGSize viewSize = self.frame.size; CGFloat tmp; float vision = [[[UIDevice currentDevice] systemVersion] floatValue]; // CCLOG("系统版本 = %f",vision); // if ( vision >= 8.0) { if([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft ||[[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) { tmp = begin.size.width; begin.size.width = begin.size.height; begin.size.height = tmp; tmp = end.size.width; end.size.width = end.size.height; end.size.height = tmp; tmp = viewSize.width; viewSize.width = viewSize.height; viewSize.height = tmp; tmp = begin.origin.x; begin.origin.x = begin.origin.y; begin.origin.y = viewSize.height - tmp - begin.size.height; tmp = end.origin.x; end.origin.x = end.origin.y; end.origin.y = viewSize.height - tmp - end.size.height; } } double aniDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; switch ([[UIApplication sharedApplication] statusBarOrientation]) { case UIInterfaceOrientationPortrait: begin.origin.y = viewSize.height - begin.origin.y - begin.size.height; end.origin.y = viewSize.height - end.origin.y - end.size.height; break; case UIInterfaceOrientationPortraitUpsideDown: begin.origin.x = viewSize.width - (begin.origin.x + begin.size.width); end.origin.x = viewSize.width - (end.origin.x + end.size.width); break; case UIInterfaceOrientationLandscapeLeft: tmp = begin.size.width; begin.size.width = begin.size.height; begin.size.height = tmp; tmp = end.size.width; end.size.width = end.size.height; end.size.height = tmp; tmp = viewSize.width; viewSize.width = viewSize.height; viewSize.height = tmp; tmp = begin.origin.x; begin.origin.x = begin.origin.y; begin.origin.y = viewSize.height - tmp - begin.size.height; tmp = end.origin.x; end.origin.x = end.origin.y; end.origin.y = viewSize.height - tmp - end.size.height; break; case UIInterfaceOrientationLandscapeRight: if ( vision < 8.0) { tmp = begin.size.width; begin.size.width = begin.size.height; begin.size.height = tmp; tmp = end.size.width; end.size.width = end.size.height; end.size.height = tmp; tmp = viewSize.width; viewSize.width = viewSize.height; viewSize.height = tmp; tmp = begin.origin.x; begin.origin.x = begin.origin.y; begin.origin.y = tmp; tmp = end.origin.x; end.origin.x = end.origin.y; end.origin.y = tmp; } else { tmp = begin.size.width; begin.size.width = begin.size.height; begin.size.height = tmp; tmp = end.size.width; end.size.width = end.size.height; end.size.height = tmp; tmp = viewSize.width; viewSize.width = viewSize.height; viewSize.height = tmp; tmp = begin.origin.x; begin.origin.x = begin.origin.y; begin.origin.y = viewSize.height - tmp - begin.size.height; tmp = end.origin.x; end.origin.x = end.origin.y; end.origin.y = viewSize.height - tmp - end.size.height; } break; default: break; } float scaleX = cocos2d::CCEGLView::sharedOpenGLView()->getScaleX(); float scaleY = cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); if (self.contentScaleFactor == 2.0f) { // Convert to pixel coordinate begin = CGRectApplyAffineTransform(begin,CGAffineTransformScale(CGAffineTransformIdentity,2.0f,2.0f)); end = CGRectApplyAffineTransform(end,2.0f)); } float offestY = cocos2d::CCEGLView::sharedOpenGLView()->getViewPortRect().origin.y; CCLOG("offestY = %f",offestY); if (offestY < 0.0f) { begin.origin.y += offestY; begin.size.height -= offestY; end.size.height -= offestY; } // Convert to desigin coordinate begin = CGRectApplyAffineTransform(begin,1.0f/scaleX,1.0f/scaleY)); end = CGRectApplyAffineTransform(end,1.0f/scaleY)); cocos2d::CCIMEKeyboardNotificationInfo notiInfo; notiInfo.begin = cocos2d::CCRect(begin.origin.x,begin.origin.y,begin.size.width,begin.size.height); notiInfo.end = cocos2d::CCRect(end.origin.x,end.origin.y,end.size.width,end.size.height); notiInfo.duration = (float)aniDuration; cocos2d::CCIMEDispatcher* dispatcher = cocos2d::CCIMEDispatcher::sharedDispatcher(); if (UIKeyboardWillShowNotification == type) { self.keyboardShowNotification = notif; // implicit copy dispatcher->dispatchKeyboardWillShow(notiInfo); } else if (UIKeyboardDidShowNotification == type) { //CGSize screenSize = self.window.screen.bounds.size; dispatcher->dispatchKeyboardDidShow(notiInfo); caretRect_ = end; caretRect_.origin.y = viewSize.height - (caretRect_.origin.y + caretRect_.size.height + [UIFont smallSystemFontSize]); caretRect_.size.height = 0; isKeyboardShown_ = YES; } else if (UIKeyboardWillHideNotification == type) { dispatcher->dispatchKeyboardWillHide(notiInfo); } else if (UIKeyboardDidHideNotification == type) { caretRect_ = CGRectZero; dispatcher->dispatchKeyboardDidHide(notiInfo); isKeyboardShown_ = NO; } } -(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)dis { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDelegate:self]; [UIView setAnimationDuration:duration]; [UIView setAnimationBeginsFromCurrentState:YES]; //NSLog(@"[animation] dis = %f,scale = %f \n",dis,cocos2d::CCEGLView::sharedOpenGLView()->getScaleY()); if (dis < 0.0f) dis = 0.0f; dis *= cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); if (self.contentScaleFactor == 2.0f) { dis /= 2.0f; } self.frame = CGRectMake(originalRect_.origin.x,originalRect_.origin.y - dis,originalRect_.size.width,originalRect_.size.height); switch ([[UIApplication sharedApplication] statusBarOrientation]) { case UIInterfaceOrientationPortrait: self.frame = CGRectMake(originalRect_.origin.x,originalRect_.size.height); break; case UIInterfaceOrientationPortraitUpsideDown: self.frame = CGRectMake(originalRect_.origin.x,originalRect_.origin.y + dis,originalRect_.size.height); break; case UIInterfaceOrientationLandscapeLeft: if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) { self.frame = CGRectMake(originalRect_.origin.x - dis,originalRect_.origin.y,originalRect_.size.height); } else{ self.frame = CGRectMake(originalRect_.origin.x,originalRect_.size.height); } break; case UIInterfaceOrientationLandscapeRight: if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) { self.frame = CGRectMake(originalRect_.origin.x + dis,originalRect_.size.height); } break; default: break; } [UIView commitAnimations]; }
实现原理就是验证版本号。当然通过验证版本号这种方式不是很好。
3.3 已经修改过了。
原文链接:https://www.f2er.com/cocos2dx/344190.html