【问题标题】:UITextview frame resized to incorrect heightUITextview 框架调整为不正确的高度
【发布时间】:2015-10-16 02:31:47
【问题描述】:

我的视图底部有一个标签栏,我想隐藏它。我用 Saurabh 提供的代码隐藏它,here

代码运行良好,但是我添加了一行来更改文本视图的位置。但是文本视图会调整大小!代码如下:

- (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]; 

}

除了 inputView(一个 UITextview)被调整大小之外,一切都很好。如果tabbar被隐藏,textview(inputView)的高度变为58,当我再次显示tabbar时,textview的高度变为43。

我总是可以根据需要加减 7 或 8。但我认为知道是什么原因可能会很好。

谢谢!

【问题讨论】:

    标签: ios uitabbarcontroller uitextview autoresizingmask


    【解决方案1】:

    很可能是因为您的UITextViewautoresizingMask 属性设置为允许灵活的高度。下面的代码应该会有所帮助:

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

    【讨论】:

      【解决方案2】:

      尝试将inputViewautoResizingMask 属性设置为UIViewAutoresizingNone。重置文本字段的超级视图的框架可能会触发输入视图上的调整大小事件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多