直接貼代碼了:
- (CGAffineTransform)transformForOrientation { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (UIInterfaceOrientationLandscapeLeft == orientation) { return CGAffineTransformMakeRotation(M_PI*1.5); } else if (UIInterfaceOrientationLandscapeRight == orientation) { return CGAffineTransformMakeRotation(M_PI/2); } else if (UIInterfaceOrientationPortraitUpsideDown == orientation) { return CGAffineTransformMakeRotation(-M_PI); } else { return CGAffineTransformIdentity; } }
用法:(這里用一個button控件來實現)
UIButton *transformButton;
//從小變大:
[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.2]; [UIView setAnimationDelegate:self]; transformButton.transform = CGAffineTransformScale([self transformForOrientation], 1.1, 1.1); [UIView commitAnimations];
同理
//大變小
transformButton.transform = CGAffineTransformScale([self transformForOrientation], 0.001, 0.001);