- (void)viewDidLoad
{
[super viewDidLoad];
// 判断设备类型 iphone or ipad
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
viewWidth = IPHONE_VIEW_WIDTH;
viewHeight = IPHONE_VIEW_HEIGHT;
}else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
viewWidth = IPAD_VIEW_WIDTH;
viewHeight = IPAD_VIEW_HEIGHT;
}
screenSize = [[UIScreen mainScreen] bounds].size;
// 判断屏幕方向为水平或垂直 landscape or virtical
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft||
self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
screenSize = CGSizeMake(screenSize.height, screenSize.width);
}
[self createViews];
}
-(BOOL)shouldAutorotate
{
return YES; //设置设备是否可以旋转
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// 将要旋转屏幕时,改变screenSize
screenSize = [[UIScreen mainScreen] bounds].size;
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
screenSize = CGSizeMake(screenSize.height, screenSize.width);
}
[self setViewsLocation];
}