Dar*_*ius 4 c# xamarin.ios ios xamarin
我需要检测用户何时将设备旋转到横向方向.我可以通过以下代码检测方向何时改变:
UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
this.orientationObserver = UIDevice.Notifications.ObserveOrientationDidChange(MyRotationCallback);
private void MyRotationCallback(object sender, NSNotificationEventArgs e)
{
// Landscape or Portrait ?
}
Run Code Online (Sandbox Code Playgroud)
它有效,但我不知道它是否改为横向或纵向.我怎么能发现这个?
Sus*_*ver 10
UIDevice.CurrentDevice.Orientation
Run Code Online (Sandbox Code Playgroud)
LandscapeLeft
PortraitUpsideDown
LandscapeRight
Portrait
Run Code Online (Sandbox Code Playgroud)
在你ViewDidLoad(或类似):
Foundation.NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UIDeviceOrientationDidChangeNotification"), DeviceRotated);
Run Code Online (Sandbox Code Playgroud)
void DeviceRotated(NSNotification notification)
{
System.Diagnostics.Debug.WriteLine(UIDevice.CurrentDevice.Orientation);
}
Run Code Online (Sandbox Code Playgroud)
LandscapeLeft
PortraitUpsideDown
LandscapeRight
Portrait
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2042 次 |
| 最近记录: |