2010-08-22 58 views
3

我正在嘗試爲圖像創建投影。我也有意見之間的動畫,這是背景。但是,當我使用下面的代碼時,圖像不繪製。有人有主意嗎?需要幫助才能在iOS4的uiview中將圖像添加到圖像中?

self.frontViewBackground = [[[UIView alloc] initWithFrame:frame] autorelease]; 
//self.frontViewBackground.image = [UIImage imageNamed:@"whitepaper3.png"]; 
self.frontViewBackground.multipleTouchEnabled = YES; 
[self.photoView addSubview:self.frontViewBackground]; 

UIImage *image = [UIImage imageNamed:@"whitepaper3.png"]; 

CGContextRef ctx = UIGraphicsGetCurrentContext(); 

CGContextSetShadow(ctx, CGSizeMake(1, -2), 3.0); 
[image drawInRect:self.frontViewBackground.frame blendMode:kCGBlendModeNormal alpha:1.0]; 
CGContextRestoreGState(ctx); 

回答

2

您是否想過使用CALayer的陰影屬性?例如,你可以做到以下幾點:

UIView *view = [[UIView alloc] initWithFrame:frame]; 
view.layer.shadowColor = [[UIColor blackColor] CGColor]; 
view.layer.shadowRadius = 5.0 

簽出更多的位置:http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instp/CALayer/shadowColor

+1

如果你這樣做,你還需要使用是'shadowPath'或'shouldRasterize'進行調查,如使用CALayer的陰影沒有路徑,沒有光柵化是相當低效的。 – 2010-08-22 04:44:49

相關問題