xcode 隐藏 UIToolBar 和 UINavigation 并展开 UIWebView?- iOS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14097289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:25:24  来源:igfitidea点击:

Hide UIToolBar and UINavigation and Expand UIWebView? - iOS

iosxcodeuiwebviewhideuigesturerecognizer

提问by Mina Dawoud

Is it possible to hide a UIToolBarand UINavigationBarand to do so with a UITouchGestureRecognizerbut at the same time Expand the UIWebViewso it takes up the rest of the space? Also to do the same thing in reverse after?

是否可以隐藏 a UIToolBarandUINavigationBar并使用 aUITouchGestureRecognizer但同时展开 theUIWebView以占用其余空间?反过来做同样的事情后?

Thanks to all in advance!

提前感谢大家!

采纳答案by D_D

use

-(void)didTap
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
//remove your tool bar from superview
[toolbar removeFromSuperview];
//code to add ur UIWebView

}

回答by bobnoble

To hide top navigation bar use either the navigationBarHiddenproperty or setNavigationBarHidden:animated:method if you want it animated. Similarly, use toolbarHiddenproperty or setToolbarHidden:animated:method for the bottom toolbar. These are part of UINavigationController.

要隐藏顶部导航栏,如果您希望它具有动画效果,请使用navigationBarHidden属性或setNavigationBarHidden:animated:方法。同样,使用底部工具栏的toolbarHidden属性或setToolbarHidden:animated:方法。这些是UINavigationController.

If you want to animate both the toolbars hiding and the UIWebViewexpanding, wrap the change in size of the UIWebViewin a UIView animateWithDuration...method.

如果要同时为工具栏隐藏和UIWebView扩展设置动画,请将 的大小更改包装UIWebView在一个UIView animateWithDuration...方法中。

Add the gesture recognizer of your choice. For a swipe, create an instance UISwipeGestureRecognizerand add it to your view. Something like this in your viewDidLoadmethod:

添加您选择的手势识别器。对于滑动,创建一个实例UISwipeGestureRecognizer并将其添加到您的视图中。在你的viewDidLoad方法中是这样的:

UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe)];
[self.view addGestureRecognizer:swipeGestureRecognizer]; 

And the swipe handler as something like this:

和滑动处理程序是这样的:

-(void)handleSwipe{
    if (self.navigationController.navigationBarHidden) {
       [self.navigationController setNavigationBarHidden:NO animated:YES];
        [self.navigationController setToolbarHidden:NO animated:YES];
       [UIView animateWithDuration:0.3 animations:^{
            self.webView.frame = CGRectMake(self.webView.frame.origin.x, self.webView.frame.origin.y, self.webView.frame.size.width, self.webView.frame.size.height - 88);
        }];
    } else {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        [self.navigationController setToolbarHidden:YES animated:YES];
        [UIView animateWithDuration:0.3 animations:^{
            self.webView.frame = CGRectMake(self.webView.frame.origin.x, self.webView.frame.origin.y, self.webView.frame.size.width, self.webView.frame.size.height + 88);
       }];
    }
}