아이폰의 판단 화면 방향

1303 단어 iPhone
두 가지 방법으로 판단할 수 있다
1, 프로그램이 막 실행되기 시작했을 때 현재 방향을 가져올 수 없습니다.너에게 몇 가지 방법을 말해 줄 테니, 네가 한번 해 봐라.시작 후 0.01초 동안 초기화된 코드를 실행할 수 있으며, 이때 장치 방향을 얻을 수 있습니다.
2. 다른 방법으로 상태막대의 방향을 빌린다.
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];	




3. 컨트롤러에 속하는 컨트롤러의 인터페이스 방향을 가져와서 관련 컨트롤러의 방향이 컨트롤러의 방향과 일치하도록 할 수 있다. 현재의 장치 방향이 무엇인지 신경 쓰지 않아도 된다.컨트롤러의 인터페이스 방향은interfaceOrientation 속성에서 사용할 수 있습니다.예를 들면 다음과 같습니다.
if (self.interfaceOrientation == UIDeviceOrientationPortrait)


프로그램이 시작될 때 프로트랙트 방향에 있는지 아닌지를 판단할 수 있다.
if(self.interfaceOrientation== UIDeviceOrientationPortrait ||self.interfaceOrientation== UIDeviceOrientationPortraitUpsideDown)
{//정
else
{//반대
}
 
2, 아래의 방법은 아날로그에서 앱을 시작한 후 장치의 방향을 얻을 수 없다는 것을 발견했다.결과는 UIDeviceOrientationUnknown입니다.The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications. 어떤 이는 진짜 기기에서만 가능하다고 한다.
UIDevice *device = [UIDevicecurrentDevice];
if(device.orientation== UIInterfaceOrientationPortrait || device.orientation== UIInterfaceOrientationPortraitUpsideDown)
{//정
else
{//반대
}

좋은 웹페이지 즐겨찾기