简体   繁体   中英

UITextview frame resized to incorrect height

I have a tabbar at the bottom of my view which I would like to hide. I am hiding it with the code provided by Saurabh, here .

The code works great, however I've added a line to change the location of my text view. But the text view gets resized! Here is the code:

- (void) hideTabBar:(UITabBarController *) tabbarcontroller {


    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, 480.0f, view.frame.size.width, view.frame.size.height)];
        } 
        else 
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480.0f)];
        }

    }
    [buttonView setFrame:CGRectMake(0.0, 154.0, 320.0, 306.0)];
    [screenImageView setFrame:CGRectMake(0.0, 16.0, 320.0, 139.0 )];
    [inputView setFrame:CGRectMake(20.0f, 105.0f, 280.0f, 50.0f)];

    [UIView commitAnimations];

}

- (void) showTabBar:(UITabBarController *) tabbarcontroller {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in tabbarcontroller.view.subviews)
    {        
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, 431.0f, view.frame.size.width, view.frame.size.height)];

        } 
        else 
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431.0f)];
        }


    }
    [buttonView setFrame:CGRectMake(0.0, 105.0, 320.0, 306.0)];
    [screenImageView setFrame:CGRectMake(0.0, 16.0, 320.0, 90.0 )];
    [inputView setFrame:CGRectMake(20.0f, 56.0f, 280.0f, 50.0f)];

    [UIView commitAnimations]; 

}

Every thing works great except the inputView (a UITextview) gets resized. If the tabbar is hidden, the height of the textview (inputView) becomes 58, and when I show the tabbar again, the height of the textview becomes 43.

I could always just add or subtract 7, or 8 as needed. But I thought it might be good to know what is causing this.

Thanks!

Most likely it is because the autoresizingMask property of your UITextView is set to allow for a flexible height. Something like the code below should help:

inputView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin; // Pins inputView to the top

Try setting the autoResizingMask property of your inputView to UIViewAutoresizingNone . It is possible that resetting the frame of the superview of the text field is triggering a resize event on the input view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM