ShouldAutorotateToInterfaceOrientation은 장치 방향이 변경 될 때마다 호출됩니다.
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
Console.Out.WriteLine(toInterfaceOrientation.ToString());
// Return true for supported orientations
// This particular screen is landscape only!
return (toInterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || toInterfaceOrientation == UIInterfaceOrientation.LandscapeRight);
}
이 코드는 뷰가 landscapeleft 또는 landscaperight 모드에서 자신의 방향을 허용하고 콘솔에 매번 새로운 장치 방향을 기록합니다.
뷰를로드 및 UINavigationController가하지만, 세로 모드에서 여전히 (예를 들어)으로 푸시 (그리고 ShouldAutorotateToInterfaceOrientation가 호출되지 않습니다.)
을 목표 - C에서
, 그것은 강제로 매우 쉽게 장치 방향이지만 MonoTouch에서는 직접 매핑이없는 것처럼 보입니다.
상기 용액;
우리가 원하는 방향을 지정하여 objective-c 런타임에 메시지를 보냅니다.
당신은 쉽게보기 컨트롤러에 다음을 추가하여이 작업을 수행 할 수 있습니다
Selector orientationSetter;
private void SetOrientation (UIInterfaceOrientation toOrientation)
{
if (orientationSetter == null)
{
orientationSetter = new Selector ("setOrientation:");
}
Messaging.void_objc_msgSend_int (UIDevice.CurrentDevice.Handle,
orientationSetter.Handle, (int)toOrientation);
}
이제 수동으로 전체 장치의 방향을 변경할 수 있습니다. 게다가 UINavigationController를 사용하면이 뷰가 스택 밖으로 팝되면 방향이 정상으로 돌아갑니다.
ShouldAutorotateToInterfaceOrientation을 재정 의하여 true를 반환했다고 말하면 다음을 반환한다는 것을 의미합니까? : return toInterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || toInterfaceOrientation == UIInterfaceOrientation.LandscapeRight; – Anuj