Monotouch在纵向/横向中旋转视图

Tim*_*ett 7 iphone xamarin.ios

任何人都可以举例说明如何将单点触控应用程序的视图从纵向旋转到横向,反之亦然?

Fra*_*ger 8

如果在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将自动适应.


Bir*_*chi 1

这是你可以尝试的。

如果您想在触摸视图时更改视图方向,请按照以下步骤操作

  1. 在视图内实现 TouchBegan 方法。

  2. 在touchesBegan方法中检查当前设备方向, [[UIDevice currentDevice] orientation];

  3. 如果您想更改方向,请在视图上使用 CGAffineTransformation 方法,如下所示viewRef.transform = CGAffineTransformMakeRotation(angle);