Created
July 20, 2017 04:38
-
-
Save ccy/82af31bcb6c376762ee92b196643d0e3 to your computer and use it in GitHub Desktop.
FireMonkey: Detect device orientation change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uses System.Messaging, FMX.Platform; | |
var FId: Integer; | |
// Subscribe to TOrientationChangedMessage | |
FId := TMessageManager.DefaultManager.SubscribeToMessage(TOrientationChangedMessage, DoOrientationChanged); | |
// Write orientation change handler: | |
procedure TMyForm.DoOrientationChanged(const Sender: TObject; const M: TMessage); | |
var s: IFMXScreenService; | |
begin | |
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, s) then begin | |
case s.GetScreenOrientation of | |
TScreenOrientation.Portrait: ; | |
TScreenOrientation.Landscape: ; | |
TScreenOrientation.InvertedPortrait: ; | |
TScreenOrientation.InvertedLandscape: ; | |
end; | |
end; | |
end; | |
// Unsubscribe the TOrientationChangedMessage | |
TMessageManager.DefaultManager.Unsubscribe(TOrientationChangedMessage, FId); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment