【问题标题】:Monotouch iPhone Landscape ModeMonotouch iPhone 横向模式
【发布时间】:2010-12-10 22:12:21
【问题描述】:
从 xib 加载新的视图控制器时,如何让 Monotouch iPhone 应用程序保持横向模式?
在我使用的应用加载时切换到横向模式:
app.StatusBarOrientation = UIInterfaceOrientation.LandscapeRight;
我希望能够在界面生成器中旋转视图并设计界面。我可以点击界面构建器视图角落的旋转箭头来旋转它并保存,但它在运行时不会影响应用程序。
【问题讨论】:
标签:
c#
iphone
xamarin.ios
landscape
xib
【解决方案1】:
这个链接Monotouch rotate view in Portrait/Landscape说要使用:
viewRef.transform = CGAffineTransformMakeRotation(angle);
所以我尝试了
this.view.Transform = CGAffineTransformMakeRotation(3.141f * 0.5f);
但我得到了奇怪的结果。原来我使用的是 .view 而不是 .View。现在它适用于:
this.View.Transform = CGAffineTransformMakeRotation(3.141f * 0.5f);
【解决方案2】:
使用这个不是更简单吗:
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return ((toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown) && (toInterfaceOrientation != UIInterfaceOrientation.Portrait));
}
这样它只会在设备处于横向模式(两个横向)时自动旋转