bytelee
2014-01-19 11:28:52 +08:00
直接贴给你方法看看吧:
- (void)setOristation:(UIDeviceOrientation)oritation
{
if (oritation != [[UIDevice currentDevice] orientation] && [[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
{
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = oritation;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
CGRect bounds = [[UIScreen mainScreen] bounds];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:2];
CGRect frame = CGRectZero;
if(oritation == UIDeviceOrientationLandscapeLeft)
{
frame = CGRectMake(bounds.size.width-20, 0, 20, bounds.size.height);
}
else if(oritation == UIDeviceOrientationLandscapeRight)
{
frame = CGRectMake(0, 0, 20, bounds.size.height);
}
else if(oritation == UIDeviceOrientationPortraitUpsideDown)
{
frame = CGRectMake(0, bounds.size.height-20, bounds.size.width, 20);
}
else if(oritation == UIDeviceOrientationPortrait)
{
frame = CGRectMake(0, 0, bounds.size.width, 20);
}
self.statusBarView.frame = frame;
[UIView commitAnimations];
}
[UIViewController attemptRotationToDeviceOrientation];
}