iOS 6でビューの向きを変更したい。向きを変更したときに、ビューのフレームサイズを設定したい。
向きを変更するための私のサンプルコード:
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSInteger)supportedInterfaceOrientations
{
NSInteger mask = 0;
intOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(intOrientation == UIInterfaceOrientationPortrait || intOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
mask |= UIInterfaceOrientationMaskPortrait;
} else
if(intOrientation == UIInterfaceOrientationLandscapeLeft)
{
mask |= UIInterfaceOrientationMaskLandscapeLeft;
}
}
NSLog (@"mask %d",mask);
return mask;
}
// Here now mask value is 2 because my default mode is portrait.
向きを横向きに変更するときに、フレームサイズを設定します。その方法を教えてください。
ok ..バージョンを取得してviewdidLoadで比較することにより、disのようなビューのフレームサイズを設定できますか?
orientation = [[UIDevice currentDevice] orientation];
NSString *reqSysVer = @"6.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
NSLog (@"ios version %@",currSysVer);
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
if (orientation == UIInterfaceOrientationMaskPortrait) {
self.view.frame = CGRectMake(0, 0, 1000, 800);
self.tableView1.frame = CGRectMake(1, 0, 764,510);
}
else if (orientation == UIInterfaceOrientationMaskLandscapeLeft)
{
self.view.frame = CGRectMake(0, 0, 1300, 370);
self.tableView1.frame = CGRectMake(0, 0, 1300, 370);
self.view.backgroundColor = [UIColor blackColor];
}
}