代码摘自OpenFeint源码:
+ (void)transformView:(UIView*)view toOrientation:(UIInterfaceOrientation)orientation
{
CGAffineTransform newTransform =CGAffineTransformIdentity;
CGRect bounds = [[UIScreenmainScreen] bounds];
CGPoint center =CGPointMake(CGRectGetMidX(bounds),CGRectGetMidY(bounds));
switch (orientation)
{
caseUIInterfaceOrientationLandscapeRight:
newTransform =CGAffineTransformMake(0, 1, -1, 0, 0, 0);
bounds =CGRectMake(0.f, 0.f, bounds.size.height, bounds.size.width);
break;
caseUIInterfaceOrientationLandscapeLeft:
newTransform =CGAffineTransformMake(0, -1,1, 0, 0, 0);
bounds =CGRectMake(0.f, 0.f, bounds.size.height, bounds.size.width);
break;
caseUIInterfaceOrientationPortraitUpsideDown:
newTransform =CGAffineTransformMake(-1, 0, 0, -1, 0, 0);
break;
caseUIInterfaceOrientationPortrait:
newTransform =CGAffineTransformTranslate(newTransform, 0, 0);
break;
default:
OFAssert(NO,@"invalid orientation used");
break;
}
[view setTransform:newTransform];
view.bounds = bounds;
view.center = center;
}