2010-08-22 78 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

相关问题