我的视图底部有一个标签栏,我想隐藏它。我在这里用 Saurabh 提供的代码隐藏它。
代码效果很好,但是我添加了一行来更改我的文本视图的位置。但是文本视图会调整大小!这是代码:
- (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。但我认为知道是什么原因可能会很好。
谢谢!