Phonegap: Keyboard changes window height in iOS 7

前端 未结 9 582
一整个雨季
一整个雨季 2020-12-14 21:48

In iOS 6 everything works fine. The keyboard opens and moves the input into view. When the keyboard closes everything goes back where it should.

In iOS 7 the keyboar

9条回答
  •  执念已碎
    2020-12-14 22:30

    The Petrash's solution worked for me. But I had still problems supporting rotations on iPad. So, in the same CDVViewController.m I've added this method:

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
        [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
        if (self.webView){
            CGRect newFrame = self.webView.bounds;
            //NSLog(@"%f" , newFrame.size.height);
    
            NSString *JS =  [NSString stringWithFormat:@"viewport = document.querySelector('meta[name=viewport]'); viewport.setAttribute('content', 'user-scalable=no, initial-scale=1.0, maximum-scale=1, minimum-scale=1, width=device-width, height=%d,  target-densitydpi=device-dpi');",  (int) newFrame.size.height*1 ];
    
            [self.webView stringByEvaluatingJavaScriptFromString:JS];
        }
    
    }
    

    and, to support the "non scale" behaviour, edited the Petrash's solution in this way:

    CGRect newFrame = self.webView.bounds;
        //NSLog(@"%f" , newFrame.size.height);
    
        NSString *JS =  [NSString stringWithFormat:@"viewport = document.querySelector('meta[name=viewport]'); viewport.setAttribute('content', 'user-scalable=no, initial-scale=1.0, maximum-scale=1, minimum-scale=1, width=device-width, height=%d,  target-densitydpi=device-dpi');",  (int) newFrame.size.height*1 ];
    
        [self.webView stringByEvaluatingJavaScriptFromString:JS];
    

    KeyboardShrinksView = false

    This is hacky, but it works from 5.1 to 7.0.3. Tested on Cordova 3.0.

提交回复
热议问题