2010-11-30 2 views
0

iOS 4.2는 iPad 용으로도 사용됩니다. 아래 코드는 우리가 모두 장치를 식별하는 데 사용하는 표준 패턴입니다. 이 iPad 4.2에 대한 변경 방법은 무엇입니까? 버전이 아닌 장치 유형을 고려하도록 코드를 변경해야합니까?iPad 용 기기 식별 4.2 iOS 4.2

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200 
    CGRect frame = [[UIScreen mainScreen] bounds]; 
    self.view.frame = frame; 
#else 
    CGRect frame = [self.view bounds]; 
#endif 

답변

5

더 좋은 방법은 currentDevice 그 선택에 응답하는 것이 [[UIDevice currentDevice] userInterfaceIdiom]

먼저 체크 할 것이다. 그렇지 않다면 iOS 3.1.x 또는 이전 버전을 실행하는 iPhone/iPod입니다.

해당 선택기에 응답하는 경우 UIUserInterfaceIdiomPhone 또는 UIUserInterfaceIdiomPad에 대한 결과를 확인할 수 있습니다.

0

검사 장치 버전과 코드를 따라

float version = [[[UIDevice currentDevice] systemVersion] floatValue]; 
    if (version == 4.2) 
    { 
     CGRect frame = [[UIScreen mainScreen] bounds]; 
    self.view.frame = frame; 

    } 
else 
    self.view.frame = frame; 

를 사용하여 당신을 도울 수도 있습니다 코드입니다.

2

당신이 시도 할 수 있습니다 :

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200 

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 
    // type you code for iPad 
} else { 
    // type you code for iPhone 
} 

#endif