아이폰의 판단 화면 방향
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
{//반대
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
IOS Application core architectureA new IOS application program is mainly composed of the following files: If the app delegate class is nil, UIKit will as...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.