2013-07-11 2 views
1

XE4에 OnRotate 이벤트가있을 것이라고 생각했지만 OnResize이 사용 된 것 같습니다. 알았어.Delphi에서 iPad 방향 감지하기

그러나 기기의 방향을 결정해야합니다. 나는 그것이 간단하다는 것을 확실하다 그러나 Google는 도울 수 없다!

+0

오리엔테이션 변경시 OnResize가 더 이상 실행되지 않습니다. 새로운 솔루션을 보려면 여기를 클릭하십시오 : http://stackoverflow.com/questions/32670119/delphi-android-detect-device-orientation-change – Hans

답변

6

장치의 현재 방향을 감지하려면 UIApplication 클래스의 일부인 statusBarOrientation 메서드를 사용할 수 있습니다.

당신은 기본 폼의하여 onResize 이벤트에 내 기능을 사용할 수 있습니다이 샘플을

uses 
    iOSapi.UIKit; 

function SharedApplication:UIApplication; 
begin 
    Result:=TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication); 
end; 

procedure TForm23.Button1Click(Sender: TObject); 
var 
    LOrientation: Cardinal; 
begin 
    LOrientation := SharedApplication.statusBarOrientation; 
    if (LOrientation = UIDeviceOrientationLandscapeLeft) or (LOrientation = UIDeviceOrientationLandscapeRight) then 
    ShowMessage('Landscape') 
    else 
    if (LOrientation = UIInterfaceOrientationPortrait) then 
    ShowMessage('Portrait'); 
end; 
+0

OnRize에서 코드를 호출하면 세로 및 반전 세로로 시도해 보았습니다. : 세로 - 감지, 반전 세로 - 감지, 변경 사항 감지를 중지합니다. 어쩌면 내가 뭔가 잘못하고있는 것 같아. 내가 알아 내면 게시 할거야. –

1

높이와 너비를 확인하는 것이 그 방법이라고 봅니다. h> w이면 potrait, 그렇지 않으면 landscape. 놀란 것은 무언가 내장되어 있지 않습니다.

0

을보십시오.

기능 TERMainForm.GetOrientation : TScreenOrientation; var
오리엔테이션 S : IFMXScreenService; 시작
TPlatformServices.Current.SupportsPlatformService 경우 (IFMXScreenService, 는 IInterface (방위)) 다음
시작 결과 : = OrientationS.GetScreenOrientation;

else raise Exception.Create ('Orientation not supported'); 끝;