The general idea will be to get a UIView 's layer to draw itself into a context and then grab a UIImage out of it.
Up vote 1 down vote favorite share g+ share fb share tw.
I have a UIView with a transparent background, and some buttons. I would like to capture the drawing of the view, shrink it, and redraw (mirror) it elsewhere on the screen. (On top of another view.
) The buttons can change, so it isn't static. What would be the best way to do this? Ios uiview uikit core-graphics calayer link|improve this question asked Dec 30 '11 at 3:25Jay520213 92% accept rate.
The general idea will be to get a UIView's layer to draw itself into a context and then grab a UIImage out of it. UIGraphicsBeginImageContext(view.frame. Size); view.
Layer renderInContext:UIGraphicsGetCurrentContext(); UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); You will also need to #import.
Thanks. – Jay Dec 30 '11 at 4:13 Yes and Yes it should preserve the transparency. – Paul.
S Dec 30 '11 at 4:15 Would it be possible to use a CGContext directly, without the overhead if a UIImage? – Jay Dec 30 '11 at 4:44 Do you have issues? Or are you trying to prematurely optimize?
– Paul. S Dec 30 '11 at 4:46 Heh, probably. But I am curious if it is possible... – Jay Dec 30 '11 at 4:52.
If you don't really need to capture the drawing (from what you describe, it seems unlikely that you need an image), create another instance of the view and apply a transform. Something like... UIView* original UIView alloc initWithFrame:originalFrame; UIView* copy = UIView alloc initWithFrame:copyFrame; // Scale down 50% and rotate 45 degrees // CGAffineTransform t = CGAffineTransformMakeScale(0.5, 0.5); copy. Transform = CGAffineTransformRotate(t, M_PI_4); someSuperView addSubview:original; someSuperView addSubview:copy; // release, etc. I added the rotation just to show that you can do a variety of different things with transformations.
– nloko Dec 30 '11 at 4:45 Updated answer for clarity. – nloko Dec 30 '11 at 4:50 But how are the two UIViews connected? I don't see why copy would draw the contents of original in your sample code.
– Jay Dec 30 '11 at 4:53 Recreating a view hierarchy is surely more expensive then ... getting an image based on the contents of the current bitmap-based graphics context – Paul. S Dec 30 '11 at 4:54.
Check a nice sample code saveme-dot-txt.blogspot.com/2011/06/dyna... following WWDC sessions. It uses CAReplicatorLayer for reflection, pretty easy to implement and looks really smooth and impressive.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.