SetFrame works on the iPhone, but not on the iPad. Autoscale mask?

I am trying to resize a UITextView when the keyboard shows. It works beautifully on the iPhone. When the system sends a keyboard notification, the text size changes. When this is done, I will resize it to fill the initial space. (Yes, I suppose the keyboard will disappear when editing stops. I have to change this. However, I don't think my problem is.)

When I resize text on the iPad, the frame size changes correctly, but the application seems to reset the Y value for the frame to zero. Here is my code:

- (void) keyboardDidShowWithNotification:(NSNotification *)aNotification{

//
//  If the content view being edited
//  then show shrink it to fit above the keyboard.
//

if ([self.contentTextView isFirstResponder]) {

    //
    //  Grab the keyboard size "meta data"
    //

    NSDictionary *info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    //
    //  Calculate the amount of the view that the keyboard hides.
    //
    //  Here we do some confusing math voodoo.
    //
    //  Get the bottom of the screen, subtract that 
    //  from the keyboard height, then take the 
    //  difference and set that as the bottom inset 
    //  of the content text view.
    //

    float screenHeightMinusBottom = self.contentTextView.frame.size.height + self.contentTextView.frame.origin.y;

    float heightOfBottom = self.view.frame.size.height - screenHeightMinusBottom;


    float insetAmount = kbSize.height - heightOfBottom;

    //
    //  Don't stretch the text to reach the keyboard if it shorter.
    //

    if (insetAmount < 0) {
        return;
    }

    self.keyboardOverlapPortrait = insetAmount;

    float initialOriginX = self.contentTextView.frame.origin.x;
    float initialOriginY = self.contentTextView.frame.origin.y;

    [self.contentTextView setFrame:CGRectMake(initialOriginX, initialOriginY, self.contentTextView.frame.size.width, self.contentTextView.frame.size.height-insetAmount)];


}

Why does it work on the iPhone and not on the iPad? Also, can my masks autoresist unexpected changes?

+5
1

@bandejapaisa, , , .

-, kbSize.height , . , UIViewController, :

float insetAmount = (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)?kbSize.height:kbSize.width) - heightOfBottom;

self.interfaceOrientation ( ), UIInterfaceOrientationIsPortrait YES, - ( ). kbSize.height, Portrait, kbSize.width, Landscape, , .

, self.view.frame.size.height. :

float heightOfBottom = (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)?self.view.frame.size.height:self.view.frame.size.width) - screenHeightMinusBottom;

, ...

+3

All Articles