【问题标题】:Animating UInavigationBar offscreen leaves black rectangle动画 UInavigationBar 离屏留下黑色矩形
【发布时间】:2012-03-12 02:13:56
【问题描述】:

当模态 UIView 出现时,我想将 UINavigationBar 显示在屏幕上,就像在 Reeder 中一样。

我正在使用出色的 SVWebViewController (https://github.com/samvermette/SVWebViewController) 来处理从 shouldStartLoadWithRequest 中创建 Web 浏览器

动画代码来自http://www.theappcodeblog.com/2011/06/02/iphone-app-animation-tutorial-animate-a-uiview-frame/

导航栏中的所有内容都放置在屏幕外,但留下的空间(我想将其动画化)是黑色的。视图/webview 的其余部分是白色的。

如何将分配给导航栏的空间设置为白色,即视图的背景为白色? 没有xib。

我在 SVWebViewController 中找不到任何提及导航栏(仅添加工具栏)

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"They clicked: %@", request);

    NSURL *requestURL = [request URL];

    if ([[requestURL scheme ] isEqualToString: @"http"] || [[requestURL scheme] isEqualToString: @"https"]) {


            NSLog(@"Web link %@",requestURL);

            SVModalWebViewController *webViewController = [[SVModalWebViewController alloc] initWithURL:requestURL];
            webViewController.modalPresentationStyle = UIModalPresentationFullScreen;
            webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

            webViewController.availableActions = SVWebViewControllerAvailableActionsOpenInSafari | SVWebViewControllerAvailableActionsCopyLink | SVWebViewControllerAvailableActionsMailLink;

            // ios5

            if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) {

                // Create image for navigation background - portrait
                UIImage *NavigationPortraitBackground = [[UIImage imageNamed:@"navbar_bg_portrait~iPad"]
                                                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

                // Create image for navigation background - landscape
                UIImage *NavigationLandscapeBackground = [[UIImage imageNamed:@"navbar_bg_portrait~iPad"]
                                                          resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

                // Set the background image all UINavigationBars
                [[UINavigationBar appearance] setBackgroundImage:NavigationPortraitBackground forBarMetrics:UIBarMetricsDefault];
                [[UINavigationBar appearance] setBackgroundImage:NavigationLandscapeBackground forBarMetrics:UIBarMetricsLandscapePhone];

                [[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];

                // The tintcolor affects the button colour
                UIColor* col = OPAQUE_HEXCOLOR(0xdb536a);
                [[UIBarButtonItem appearance] setTintColor:col];

            } else {

                // Style the Nav Bar ios4
                [webViewController.navigationBar applyCustomTintColor];

            }
            [self presentModalViewController:webViewController animated:YES];


            // -> This code hides the UINavigationBar before animation

            CGRect navBarFrame = webViewController.navigationBar.frame;

            navBarFrame.origin.y = -navBarFrame.size.height;

            // set the position of the bar
            webViewController.navigationBar.frame = navBarFrame;

            // <- end Hide code


            return NO;

        }

    return YES;
}

TIA

【问题讨论】:

    标签: iphone ios uiwebview uinavigationcontroller uinavigationbar


    【解决方案1】:

    如果您为 UINavigationBar 设置动画,则更改留下区域颜色的答案是

    self.navigationController.view.backgroundColor = [UIColor redColor];

    【讨论】:

      【解决方案2】:

      如果您想将 NavBar 移到屏幕外,此位置当前没有任何内容,这就是它为黑色的原因。
      您应该尝试通过调整其 frame 属性来放大 WebView 以填充 NavBar 先前覆盖的空间。

      【讨论】:

      • 通过设置 uiwebview 掩码?如果是这样,那么设置是什么(我是 xib 粉丝!)
      • 我没有使用 xib... 这是初始化代码 - (void)loadView { mainWebView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; [mainWebView setBackgroundColor:[UIColor greenColor]]; mainWebView.delegate = self; mainWebView.scalesPageToFit = 是; [mainWebView loadRequest:[NSURLRequest requestWithURL:self.URL]]; self.view = mainWebView; }
      【解决方案3】:

      在控制器和 Web 视图的 nib 文件中,将 Web 视图上的自动调整大小掩码设置为自动调整高度和宽度。然后就可以了。

      【讨论】:

      • 正如我提到的类没有xib
      猜你喜欢
      • 2019-11-15
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多