2011-08-11 7 views
0

내 텍스트 필드가 어떤 방향 으로든 움직이기를 원합니다.오리엔테이션 문제

그러나 풍경의 오른쪽과 세로가 거꾸로되어있어 문제가 있습니다.

내가 그 중 하나에 방향을 지정할 때 뷰 아래로 내 텍스트 필드가 올라가지 않지만 위에있는 텍스트 필드가 올라간다.

몇 가지 해결책을 제안합니다.

아래는 내가 방향으로 사용하는 코드입니다.

나는 아이 스티 개발에 니와 마찬가지로 모든 절차를 제안 해주십시오.

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
CGRect textFieldRect=[self.view.window convertRect:textField.bounds fromView:textField]; 
CGRect viewRect=[self.view.window convertRect:self.view.bounds fromView:self.view]; 

CGFloat midLine=textFieldRect.origin.y+0.5*textFieldRect.size.height; 
CGFloat numerator=midLine-viewRect.origin.y-MINIMUM_SCROLL_FRACTION*viewRect.size.height; 
CGFloat denominator=(MAXIMUM_SCROLL_FRACTION-MINIMUM_SCROLL_FRACTION)*viewRect.size.height; 

CGFloat heightFraction=numerator/denominator; 
if(heightFraction < 0.0) 
{ 
    heightFraction=0.0; 
} 
else if(heightFraction > 1.0) 
{ 
    heightFraction=1.0; 
} 

CGRect viewFrame; 
UIInterfaceOrientation orientation=[[UIApplication sharedApplication]statusBarOrientation]; 
//code for text field editing in landscape an portrait mode 

if(orientation==UIInterfaceOrientationPortrait||orientation==UIInterfaceOrientationPortraitUpsideDown) 
{ 
    animatedDistance=floor(PORTRAIT_KEYBOARD_HEIGHT*heightFraction); 
} 
else 
{ 
    animatedDistance=floor(LANDSCAPE_KEYBOARD_HEIGHT*heightFraction); 
} 

if (orientation==UIInterfaceOrientationPortrait) { 
    viewFrame=self.view.frame; 
    viewFrame.origin.y-=animatedDistance; 
} 
else if(orientation==UIInterfaceOrientationPortraitUpsideDown){ 
    viewFrame=self.view.frame; 
    viewFrame.origin.y+=animatedDistance; 
} 
else if(orientation == UIInterfaceOrientationLandscapeRight){ 
    viewFrame=self.view.frame; 
    viewFrame.origin.x+=animatedDistance; 

} 
else if(orientation == UIInterfaceOrientationLandscapeLeft){ 

    viewFrame=self.view.frame; 
    viewFrame.origin.x-=animatedDistance; 
} 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION]; 
[self.view setFrame:viewFrame]; 

[UIView commitAnimations]; 
} 

답변

0

귀하의 ViewController에서 - willRotateToInterfaceRotation : duration 메서드를 재정의하십시오. 이 메시지는 사용자가 장치를 회전 할 때 호출됩니다. 이 방법에서는 모든 뷰를 적절한 위치에 배치 할 수 있습니다. 기준에 회전 이벤트보기에 응답을 참조하십시오 : UIViewController reference

는이 같은 것을 할 수있는 :

+0

을 회전 할 때

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if(toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown){ yourView.frame = CGRectMake(x,y,w,h); //and set the proper coordinate for this view in this orientation } 

다음이 제대로 배치되지 않은 모든 귀하의 의견을 위해 그것을 할을하지만 난 해달라고 내 풍경 오른쪽 및 거꾸로 모드에서 알 수 ...보기 아래로 텍스트 필드 키보드로 덮여지고있다 ... 어떤 설정을 작성합니다 - willRotateToInterfaceRotation : 기간 메서드? ... 위의 내 코드를보고 나를 설명 해주십시오 textFieldDidBeginEditing 메서드 중 ... O_o –

+0

위를보세요. 일부 코드를 추가했습니다. – broch

+0

사실 내 아이폰 앱에서는 키보드 위에 텍스트 필드를 표시하기 위해 위 코드를 사용하여보기를 들었습니다. 내 응용 프로그램은 네 가지 인터페이스 방향 모두를 지원합니다. 다음 코드를 사용하여 뷰를 들어 올립니다. 여기서 문제는 세로 방향에서만 작동한다는 것입니다. 네 방향 모두에서 정확한 들어 올리기를 구현할 수있는 방법이 있습니까? –