如何在iPhone中的视图上绘制导航栏和工具栏?

时间:2011-08-05 09:53:44

标签: iphone uiwebview height

我想用户点击一下uiwebview全屏?

所以我想到了修复uiwebview的高度并在内容的顶部和底部插入一些空格。因此,当用户选项卡时,导航栏和工具栏会生动地隐藏。

但问题是我无法修复uiwebview的高度,当用户点击它时,条形图会被隐藏但是uiwebview会移动到该视图,并且视图仅在半屏幕中显示。

请告诉我修复UIwebview大小的方法,以便在其上方绘制导航栏和工具栏。

向我提供任何示例代码。

4 个答案:

答案 0 :(得分:1)

试试这个webView.autoResizingMask = UIViewAutoresizingFlexibleHeight;

答案 1 :(得分:0)

webView中的UIAutoresingMask值是什么?默认情况下(在Interface Builder中)它是完整模式。尝试改变它。

答案 2 :(得分:0)

我有同样的功能。 如果用户向下滑动3个手指,则工具栏将在屏幕外动画,并且动画网页视图将填充屏幕。

我的代码:

static BOOL toolbarHidden = NO;

- (void)increaseScreensizeGestureDone
{
    // toolbar animation
    [UIView beginAnimations:@"toolbar" context:nil];

    if (toolbarHidden) 
    {
        toolbar.frame = CGRectOffset(toolbar.frame, 0, +toolbar.frame.size.height);
        toolbar.alpha = 1;
        toolbarHidden = NO;

        webView.frame = CGRectMake(0, 
                                   webView.frame.origin.y + toolbar.frame.size.height, 
                                   webView.frame.size.width, 
                                   webView.frame.size.height - toolbar.frame.size.height); 
    }
    else 
    {
        toolbar.frame = CGRectOffset(toolbar.frame, 0, -toolbar.frame.size.height);
        toolbar.alpha = 0;
        toolbarHidden = YES;

        webView.frame = CGRectMake(0, 
                                   webView.frame.origin.y - toolbar.frame.size.height, 
                                   webView.frame.size.width, 
                                   webView.frame.size.height + toolbar.frame.size.height);
    }

    [UIView commitAnimations];
}

我希望我的代码有所帮助。

编辑:

我的第一个代码也是在webview上使用'CGRectOffset',但我无法得到想要的结果。

答案 3 :(得分:0)

(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
   if(fullWebView){
     [self.navigationController hidesNavBarWhenPushed]; 
     fullWebView=FALSE;
     self.navigationController.navigationBar.hidden=TRUE;
   } 
   else { 
    [self.navigationController hidesBottomBarWhenPushed]; 
    fullWebView=TRUE; self.navigationController.navigationBar.hidden=FALSE; 
   } 
 }

(BOOL)hidesNavBarWhenPushed { 
    return (fullWebView?TRUE:FALSE)
 }

//您可以根据条件

设置UIWebView的大小