2012-05-17 3 views
-1

방향에 따라 UILable의 위치를 ​​프로그래밍 방식으로 설정하려고합니다. 하지만 Portrait로 돌아 가면 작동하지 않습니다. 사전에iPhone 오리엔테이션 변경 프레임

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     lblUserName.frame = CGRectMake(20, 200, 280, 44); 
     lblPassword.frame = CGRectMake(20, 246, 280, 44); 
    } 

    else 
    { 
     lblUserName.frame = CGRectMake(20, 220, 280, 44); 
     lblPassword.frame = CGRectMake(20, 266, 280, 44); 
    } 
} 

감사 :

여기 내 코드입니다.

+0

현재 방향 확인을 위해 toOrienation을 사용했습니다. – NSPratik

+0

statusBarOrientation 메서드를 너무 일찍 호출하면 장치가 아직 회전하지 않으므로 statusBarOrientation이 회전중인 회전을 반환합니다. – Otium

답변

2

는 라벨을 설정 programatically.And의 방향을 상태를 확인하실 수 있습니다 2 가지 가능성이 있습니다 .

1

이 IF 조건으로 시도 :

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) 
{ 

} 
else {} 
1
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
//write code here 
return YES; 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
//write code here 
} 

사용 설정 레이블 회전 장치에 대한이 두 가지 방법을. (UIInterfaceOrientation) interfaceOrientation {}

method.Otherwise하면 자동 크기 조절 마스크를 사용할 수 있습니다 : (BOOL) shouldAutorotateToInterfaceOrientation -

관련 문제