/**
* 根据当前屏幕方向,重新定义view的frame
*
* @param orientation 屏幕方向
*
* @return 适配后的frame
*/
- (CGRect)frameForOrientation:(UIInterfaceOrientation)orientation
{
CGRect frame;
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
CGRect bounds = [UIScreen mainScreen].bounds;
frame = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.height, bounds.size.width);
} else {
frame = [UIScreen mainScreen].bounds;
}
return frame;
}
//ios7
- (BOOL)shouldAutorotate
{
return YES;
}
//支持的方向
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
CGRect frame = [self frameForOrientation:interfaceOrientation];
self.webView.frame = frame;//重新定义frame
}