如果在Interface Builder中设置ui元素的几何图形,请确保在Size Inspector(Cmd + 3)中设置自动调整大小属性.然后,您可以通过单击Interface Builder中视图标题栏左上角的"旋转"按钮来查看旋转后视图的外观.
完成所有设置后,只需在ViewController中覆盖以下方法:
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
Run Code Online (Sandbox Code Playgroud)
现在在模拟器中,您可以旋转所需的所有内容,UI将自动适应.
这是你可以尝试的。
如果您想在触摸视图时更改视图方向,请按照以下步骤操作
在视图内实现 TouchBegan 方法。
在touchesBegan方法中检查当前设备方向,
[[UIDevice currentDevice] orientation];
如果您想更改方向,请在视图上使用 CGAffineTransformation 方法,如下所示viewRef.transform = CGAffineTransformMakeRotation(angle);
| 归档时间: |
|
| 查看次数: |
5684 次 |
| 最近记录: |