[英]Objective-c Change view when iphone is horizontal
我怎么知道iPhone是垂直还是水平的? 我想根据iPhone的方向切换视图。
谢谢
在UIViewController
子类中,您可以重写以下一种(或多种)方法:
willRotateToInterfaceOrientation:duration:
willAnimateRotationToInterfaceOrientation:duration:
didRotateFromInterfaceOrientation:
willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
didAnimateFirstHalfOfRotationToInterfaceOrientation:
willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
从willRotateToInterfaceOrientation:duration:
的文档说明中:
子类可以重写此方法以在旋转之前立即执行其他操作。 例如,您可以使用此方法禁用视图交互,停止媒体播放或暂时关闭昂贵的图形或实时更新。 您也可以使用它来将当前视图交换为一个反映新界面方向的视图。 调用此方法时,interfaceOrientation属性仍包含视图的原始方向。
像这样:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
// do a thing
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// some other thing
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.