我的 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。但我认为了解造成这种情况的原因可能会更好。
谢谢!
最佳答案
很可能是因为 UITextView
的 autoresizingMask
属性设置为允许灵活的高度。像下面的代码应该有帮助:
inputView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin; // Pins inputView to the top
关于ios - UITextview 框架调整为不正确的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10806079/