There are two kinds of orientation: device orientation
(UIDeviceOrientation) and interface orientation (UIInterfaceOrientation).
Interface orientation tells you whether it's portrait, portrait upside
down, landscape left, or landscape right. Device orientation has more
spatial orientations like face up or face down (i.e., how is the user
holding the device, rather than what does the screen look like). Device
orientation is much more prone to changes even when the interface doesn't
change at all (and sometimes the device doesn't know at all, hence the
"unknown"). UIDevice.CurrentDevice.Orientation gives you the device
orientation. To get interface orientation you use
UIApplication.SharedApplication.StatusBarOrientation.
You can also observe changes to the orientation by adding an observer like
this:
_interfaceNotificationHandle =
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidChangeStatusBarOrientationNotification,
HandleInterfaceOrientationDidChangeNotification);
And don't forget to unregister (in this case I do it in Dispose(), but for
a view you might want to register when the view is added to a window and
unregister when it's removed):
public void Dispose()
{
if (!_disposed)
{
if (_interfaceNotificationHandle != null)
{
NSNotificationCenter.DefaultCenter.RemoveObserver(_interfaceNotificationHandle);
_interfaceNotificationHandle = null;
}
_disposed = true;
}
}
--
Adam Kemp
[email protected]
(512) 683-6058
[email protected] wrote on 10/17/2012 06:36:31 PM:
> From: gratner <[email protected]>
> To: [email protected],
> Date: 10/17/2012 06:36 PM
> Subject: [MonoTouch] Get current orientation in a view in iOS6
> Sent by: [email protected]
>
>
> I'm running into an issue when a view needs to be aware of the current
> orientation. Before I was able to do the following:
>
> UIDevice.CurrentDevice.Orientation
>
> This does not seem to work in iOS6 (I'm on the iPad simulator) - it
returns
> "Unknown".
>
> The controller has this.InterfaceOrientation, but the view can't access
that
> directly. Does that have to be passed in from now on?
>
>
> Thanks,
> Greg
>
>
>
>
>
> --
> View this message in context: http://monotouch.
>
2284126.n4.nabble.com/Get-current-orientation-in-a-view-in-iOS6-tp4657530.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch