ios - UITextview 框架调整为不正确的高度

标签 ios uitabbarcontroller uitextview autoresizingmask

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

该代码运行良好,但是我添加了一行来更改 TextView 的位置。但是 TextView 的大小被调整了!这是代码:

- (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)被调整大小之外,一切都很好。如果隐藏标签栏,则textview(inputView)的高度变为58,当我再次显示标签栏时,textview的高度变为43。

我总是可以根据需要添加或减去 7 或 8。但我认为了解造成这种情况的原因可能会更好。

谢谢!

最佳答案

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

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

关于ios - UITextview 框架调整为不正确的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10806079/

相关文章:

ios - 将类扩展继承子句迁移到协议(protocol)扩展

ios - JTAppleCalendarView 取消选择项目时显示选定 View

swift - UITabBarController自定义页面顶栏颜色swift

ios - 用 boundingRectWithSize : 包装 UITextView

iphone - 禁用 UITextView 滚动包含 View ?

ios - 应用程序更新后将文件保留在 iOS 设备上

html - 为 UIActivityViewController 事件填充超链接属性字符串

ios - 如何创建半滑动ViewController

cocoa-touch - 使用 API 在 iOS5 上自定义 TabBar

ios - 当用户在 iOS 11 中点击时,UItextview 选择的文本不会被取消选择