장치의 현재 방향을 알고 싶습니다. 현재 장치의 UIInterfaceOrientation이 작동하지 않습니다.
if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait)
{
}
그러나이 doent 작업
장치의 현재 방향을 알고 싶습니다. 현재 장치의 UIInterfaceOrientation이 작동하지 않습니다.
if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait)
{
}
그러나이 doent 작업
내가 그것을 가지고,
if (UIDeviceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
}
이 작품을 완벽하게.
:
:[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]
은 다음 현재 방향을
EDIT를 조회 할 수 있습니다
에서 할 일 CS 다음
[[UIDevice currentDevice] orientation]
중 하나를 반환합니다
알림 생성을 시작할 필요가 없습니다. 단지 - (void) willRotateToInterfaceOrientation : (UIInterfaceOrientation) toInterfaceOrientation duration : (NSTimeInterval) duration' 및/또는 '- (void) didRotateFromInterfaceOrientation : (UIInterfaceOrientation) fromInterfaceOrientation' 메서드 – sonxurxo
(0 UIDeviceOrientationUnknown
입니다) "방향 알림 beginGeneratingDeviceOrientationNotifications
를 호출하여 활성화되지 않는 한이 속성의 값은 항상 0 반환"
UIDeviceOrientationPortrait
UIDeviceOrientationPortraitUpsideDown
UIDeviceOrientationLandscapeLeft
UIDeviceOrientationLandscapeRight
상수. 당신은 단지 있는지 확인하려면 그 상하 또는 좌우하는 경우에 상관없이, 그냥 확인 '수직'또는 '수평'
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]) {...}
당신이 방향 변경을 감지하려면
를 오버라이드 (override)-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {}
또는
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {...}
방법.
이 방법이 도움이됩니까?
수용된 대답에 언급 된 해결책이 저에게 효과적이었습니다. 내 STMT 1을 didnt는 아래의 논리
myOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(myOrientation == UIInterfaceOrientationPortrait) ||
(myOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
// stmt 1;
}
으로 실행 얻을 있지만
는
이 사람은 나를 위해 작동 바로
if (UIDeviceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
{
// stmt 1;
}
당신이 _device_ 방향을보고 있기 때문에 당신은 아마 UIDeviceOrientationPortrait``에 비교해야
_interface_ 방향이 아닙니다. 즉, 문서를 보면'UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait'라고 표시됩니다. 그래서 이것은 아무것도 바뀌지 않을 것이고, 단지 그것을 더 분명하게 만듭니다. –
beginGeneratingDeviceOrientationNotifications를 호출해야한다는 문서에도 불구하고 [[UIDevice currentDevice] orientation]이 0이 아닌 값을 반환합니다. 이유를 모르겠다. 어쩌면 내가 startAccelerometerUpdatesToQueue : withHandler : (왜?) – Jeff