views:

53

answers:

2

I'm making an iPhone-app with particles moving on a custom UIView, drawn with Core Graphics. I want my particles to leave a trace, so when the view is repainted I want it to fill the background with 0.8 alpha.

Anyone knows how to do this? I've tried setting the background color of the view to something transparent in IB, but that doesn't help, it only makes the underlying view visible through.

In short - I need help setting the clear color of UIView to something transparent.

Thanks

+1  A: 

If you want your view transparent check the opaque property. If it's opaque - no transparency will happen (http://developer.apple.com/iphone/library/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/opaque)

And you can set a clear color as the background too ([UIColor clearColor]).

krzyspmac
This only shows the underlying views. The problem persists since the whole view is still redrawn.
Accatyyc
+1  A: 

you can't have your view paint over what's already in it. Whenever drawRect is called, you have to draw the entire contents of the view from scratch.

You could instead use a CGBitmapContext to draw into, which you can keep around as long as you want. Then in your view, just draw the CGBitmapContext in its entirety into the view.

http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/CGBitmapContext/Reference/reference.html

Amorya
This is the solution I finally went with :)
Accatyyc