UIKeyboardBoundsUserInfoKey is deprecated, what to use instead?

前端 未结 9 1755
我在风中等你
我在风中等你 2020-12-02 04:56

I\'m working on an iPad app using 3.2 sdk. I\'m dealing with obtaining the keyboard size to prevent my textfields from hidding behind it.

I\'m getting a Warning in

9条回答
  •  时光取名叫无心
    2020-12-02 05:28

    - (CGSize)keyboardSize:(NSNotification *)aNotification {
        NSDictionary *info = [aNotification userInfo];
        NSValue *beginValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
    
        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    
        CGSize keyboardSize;
        if ([UIKeyboardDidShowNotification isEqualToString:[aNotification name]]) {
            _screenOrientation = orientation;
            if (UIDeviceOrientationIsPortrait(orientation)) {
                keyboardSize = [beginValue CGRectValue].size;
            } else {
                keyboardSize.height = [beginValue CGRectValue].size.width;
                keyboardSize.width = [beginValue CGRectValue].size.height;
            }
        } else if ([UIKeyboardDidHideNotification isEqualToString:[aNotification name]]) {
            // We didn't rotate
            if (_screenOrientation == orientation) {
                if (UIDeviceOrientationIsPortrait(orientation)) {
                    keyboardSize = [beginValue CGRectValue].size;
                } else {
                    keyboardSize.height = [beginValue CGRectValue].size.width;
                    keyboardSize.width = [beginValue CGRectValue].size.height;
                }
            // We rotated
            } else if (UIDeviceOrientationIsPortrait(orientation)) {
                keyboardSize.height = [beginValue CGRectValue].size.width;
                keyboardSize.width = [beginValue CGRectValue].size.height;
            } else {
                keyboardSize = [beginValue CGRectValue].size;
            }
        }
    
    
        return keyboardSize;
    }
    

提交回复
热议问题