iOS Quartz UIView integration
I'm writing an iPhone app and I'm new to the iOS sdk. Heres what I'm trying to accomplish. I want an image to flash on top of my screen (On top meaning over everything that's already in my view). I could do this fine, but I want it to be semi-transparent so I'm assuming I need to use the quartz libraries.
I implemented these two functions in a UIView class. This code that works ok but it creates a black background around the image. I want just the image with no box background around it. Is there a CGContext function I can use to alter or remove the background? Should I not be calling drawRect? Am going completely in the wrong direction? Let me know if I anyone needs more information. Thanks.
// Implements UIView
-(void)drawInContextCGContextRef)context{
CGRect imageRect;
imageRect.origin = CGPointMake(8.0, 8.0);
ima开发者_JAVA技巧geRect.size = CGSizeMake(64.0, 64.0);
CGContextSetAlpha(context, 0.5);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGContextDrawImage(context, imageRect, image);
}
-(void)drawRectCGRect)rect
{
[self drawInContext:UIGraphicsGetCurrentContext()];
}
Here's my code that calls it from the view controller.
[quartzUIView drawRect:CGRectMake(50, 50, 150, 250)];
[self.view addSubview:quartzUIView];
I think you're over-complicating it... No need to go low level.
You can use an UIImageView, just set its opacity to something you like (0.5f for instance) and be sure to set its opaque property to NO.
精彩评论