cocos2d-x 2.x 中KeyboardMove在iOS8下异常 编辑框移动异常

cocos2d-x 2.x 中KeyboardMove在iOS8下异常 编辑框移动异常,第1张

概述在向上推送过程方向不对。 #pragma mark UIKeyboard notification- (void)onUIKeyboardNotification:(NSNotification *)notif;{ NSString * type = notif.name; NSDictionary* info = [notif userInfo]; CGR


在向上推送过程方向不对。

#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];}

修改更换这两个函数 在IOS EAGLVIEw.mm中

实现原理就是验证版本号。当然通过验证版本号这种方式不是很好。

3.3 已经修改过了。

总结

以上是内存溢出为你收集整理的cocos2d-x 2.x 中KeyboardMove在iOS8下异常 编辑框移动异常全部内容,希望文章能够帮你解决cocos2d-x 2.x 中KeyboardMove在iOS8下异常 编辑框移动异常所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1045246.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存