我在iOS 5.x中通过以下方式动态地进行方向检查:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.viewProfile.frame = CGRectMake(238, 612, 295, 73);
// some more settings
}
else
{
self.profileNew.frame = CGRectMake(374, 540, 295, 58);
// some more settings
}
return YES;
}
对于iOS 6,我尝试了以下代码,但是没有起作用:
-(BOOL)shouldAutorotate{
return YES;
}
-(NSInteger)supportedInterfaceOrientations
{
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
self.viewProfile.frame = CGRectMake(238, 612, 295, 73);
// some more settings
}
else
{
self.profileNew.frame = CGRectMake(374, 540, 295, 58);
// some more settings
}
return UIInterfaceOrientationMaskAll;
}
我该如何在iOS 6中像在iOS 5.x中一样检查接口方向?
谢谢
if (UIDeviceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) { ... } else { ... }
。使用viewWillLayoutSubviews
的另一个好处是,如果你在其中更改框架,它将会被动画化。 - Levi