590Adding an UIAlertView

Unlike other UIViews, UIAlertView does not need to be added to another view via addSubView. [myAlertView show] takes care of that. Trivial, maybe. But I wasn’t aware of it.

385Rotating an UIView

Rotating an UIView, here for 90 degree.
UIImageView *v = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480, 320)];
v.center = CGPointMake(160.0, 240.0);
v.transform = CGAffineTransformMakeRotation(M_PI/2); // radian!

361Transparent Background of Custom Drawing Class

Usually common problems already have simple solution. Like that one: Problem You subclassed UIView, you want to do some custom drawing in drawRect, but no matter what you do or where you draw, the background of the view remains black.
- (void)drawRect:(CGRect)rect {
 // Drawing code
 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
 CGContextFillEllipseInRect(context, rect);
Solution In the ViewController, which call the drawing class, add
myDrawingClass.opaque = NO;
– or even nicer. In the drawing class’ init function:
self.opaque = NO;
And not like that – adding “self.opaque = NO;” in the drawRect: function – CGContextClearRect(context, rect); – CGContextSetAlpha(context, 0.5f);

355Programmatically capture UIView

Ok, a bit late to the party. Apple officially approved the use of UIGetScreenImage().
After carefully considering the issue, Apple is now allowing applications to use the function UIGetScreenImage() to programmatically capture the current screen contents. The function prototype is as follows:
CGImageRef UIGetScreenImage(void);
https://devforums.apple.com/message/149553 How to caputure a view, ideally the live input of the camera? Unfortunaly there’s no clean and clear interface for that. Only the undocumented UIGetScreenCapture() call: http://www.iphonedevsdk.com/forum/iphone-sdk-development/11219-screenshots-we-allowed-use-uigetscreenimage.html http://stackoverflow.com/questions/1531815/takepicture-vs-uigetscreenimage http://svn.saurik.com/repos/menes/trunk/iphonevnc/iPhoneVNC.mm http://blogs.oreilly.com/iphone/2008/10/creating-a-full-screen-camera.html But since UIGetScreenCapture() is an undocumented call (in 3.1), here are official ways to get the content of a view.
http://icodeblog.com/2009/07/27/1188/ http://www.elrepositorio.com/?p=31