2013-12-18 223 views
0

我開發一個應用程序,它需要對大多數的屏幕上顯示的看法一個共同的背景,讓我們說,我有我的應用程序此背景圖片:作爲當前設置的背景圖像查看背景?

enter image description here

現在想象一下,我添加表視圖和我希望我的表視圖部分視圖背景是應該在其當前位置匹配的應用程序背景圖像特定部分。我如何實現這一效果?我試着設置阿爾法爲0,但很明顯,這是當我滾動我的表會發生什麼:

我希望它看起來像往常一樣什麼:當我滾動

enter image description here

會發生什麼:

enter image description here

我也嘗試設置背景層的mask屬性,但因爲它只適用於一個視圖層,所以在這種情況下不是正確的做法。

我知道我不解釋自己真的很好,但我希望你明白至少是我想做的事情。

+0

你還需要將電池背景Alpha設置爲0。 – Macondo2Seattle

+0

除此之外,灰分離仍是一個問題。 –

+0

我回答以下,但請澄清你想達到什麼樣的,你想看到你的身後表視圖或只是在導航欄上方的整個背景是什麼? – JustAnotherCoder

回答

0

設置你的tableView背景是clearColor併爲您的tableViewCells這樣做。然後你必須隱藏分隔線。

tableView.backgroundColor = [UIColor clearColor]; 

//in your tableView cellForRowPath method 
cell.backgroundColor = [UIColor clearColor]; 
cell.separatorStyle = UITableViewCellSeparatorStyleNone; 
+0

不幸的是,它不起作用。 –

+0

您想要在整個桌面視圖上顯示整個背景還是隻顯示頂部? – JustAnotherCoder

+0

是的,我想要顯示整個背景。 –

0

您可以通過剪切您需要的圖像部分然後將其設置爲導航欄的背景來完成此操作。

這裏是切出圖像的一部分的類別:

.H

#import <UIKit/UIKit.h> 

@interface UIImage (Crop) 

-(UIImage*)cropFromRect:(CGRect)fromRect; 

@end 

.M

#import "UIImage+Crop.h" 

@implementation UIImage (Crop) 

-(UIImage*)cropFromRect:(CGRect)fromRect 
{ 
    fromRect = CGRectMake(fromRect.origin.x * self.scale, 
          fromRect.origin.y * self.scale, 
          fromRect.size.width * self.scale, 
          fromRect.size.height * self.scale); 
    CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, fromRect); 
    UIImage* crop = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation]; 
    CGImageRelease(imageRef); 
    return crop; 
} 

@end 

然後在您的viewDidLoad

//Cut out part of image where nav bar sits 
UIImage *navBG = [[UIImage imageNamed:@"cVyuX.png"] cropFromRect:CGRectMake(0, 20, 320, 44)]; 

//Set nav bar image 
[[UINavigationBar appearance] setBackgroundImage:navBG forBarMetrics:UIBarMetricsDefault]; 

//Remove gray seperator 
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]]; 

我是能夠產生這樣的:

enter image description here

+0

是的,我看到你想達到的目標,但那不是我的觀點。這不關於導航欄。它是關於表格視圖和它包含的每個單元格的剖視圖。 –

+0

@DavidRomán哦..我想我明白了。您希望底層圖像「發光」到頂部部分視圖。有點像現在他們在某個網站上做的視差事情。我在正確的軌道上嗎? – random

+0

是的,我認爲你是! –