2014-11-14 20 views
-1

下面是設置:如何在連接到UIWebView的導航欄上實現模糊的半透明效果?

  1. 背景圖像。
  2. 導航欄。
  3. 一個UIWebView。

我想要的導航欄獲取基礎上的UIWebView的內容模糊半透明的效果但這樣做的依據的背景圖像模糊。我該如何解決它?

如何將導航欄連接到UIWebView,以便在用戶向下滾動時模糊效果發生變化並正確顯示?


這裏有一個想法,我有實際工作:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    [self setAutomaticallyAdjustsScrollViewInsets:YES]; 

    self.webView = [[WKWebView alloc] init]; 
    self.webView.frame = CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height); 
    self.webView.scrollView.delegate = self; 

    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.insomnia.gr"]]]; 

    UINavigationBar *navigationBar = [[UINavigationBar alloc] init]; 
    navigationBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44); 
    navigationBar.tintColor = [UIColor clearColor]; 
    navigationBar.translucent = YES; 

    [self.view addSubview:self.webView]; 
    [self.view addSubview:navigationBar]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

#pragma mark - 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    NSLog(@"WebView - Location Y: %f Height: %f", self.webView.frame.origin.y, self.webView.frame.size.height); 

    if (scrollView.contentOffset.y >= 44) { 

     // Scale to maximum size. 
     self.webView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 
    } 
    else if (scrollView.contentOffset.y > 0) { 

     // Scale relative to content offset. 
     self.webView.frame = CGRectMake(0, 44 - scrollView.contentOffset.y, self.view.frame.size.width, self.view.frame.size.height + scrollView.contentOffset.y); 
    } 
    else { 

     // Scale to original. 
     self.webView.frame = CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height - 44); 
    } 
} 

但是,它甚至還沒有接近一個優雅和簡單的解決方案。

+0

你一定是在開玩笑吧?這是一個非常嚴重的UI問題,我實際上發佈了一個解決方案,我得到-1? – Vulkan 2014-11-15 13:51:42

回答

2

你需要移動Web視圖導航欄下,然後設置Web視圖的contentInset,像這樣:

navBar.frame = CGRectMake(0, 0, self.view.bounds.size.width, 44); 
webView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height); 
webView.scrollView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0); 
webView.scrollView.scrollIndicatorInsets = webView.scrollView.contentInset; 
+0

這不起作用。它仍然使用背景圖像。此外,它使網頁更長44像素。 – Vulkan 2014-11-14 14:36:09

+0

我創建了一個基於您的思維方式的代碼片段。 – Vulkan 2014-11-15 13:44:10

+0

我只更改:UIEdgeInsetsMake(-44,0,0,0); 謝謝! – 2014-11-20 15:05:28

0

轉到您的應用程序在Xcode和狀態欄樣式設置,點擊下拉並選擇「Light」。 這些應該適用於所有的應用程序

+0

這也不起作用。它必須是我必須改變的導航欄中的東西。 – Vulkan 2014-11-14 14:37:55