2012-01-09 66 views
0

我使用下面的代碼來移動文本框,當我點擊文本框時,使鍵盤不應該覆蓋在textfield.It工作正常與在ipad中的肖像視圖。鍵盤隱藏文本框不能在ipad中使用不同的方向

但是,當我把它旋轉到PortraitUpsideDown它不工作。而不是textField向上移動向下移動,它執行相反它在縱向orientation.I嘗試所有方式,但它不工作.plz建議我如何解決這個問題。

這個應用程序我用於iPad。

-(void) animateTextField: (UITextView *) textField up: (BOOL) up 
{ 

    int txtPosition = (textField.frame.origin.y - 540); 
    const int movementDistance = (txtPosition < 0 ? 0 : txtPosition); // tweak as needed 
    const float movementDuration = 0.3f; // tweak as needed 

    int movement = (up ? -movementDistance : movementDistance); 

    [UIView beginAnimations: @"anim" context: nil]; 
    [UIView setAnimationBeginsFromCurrentState: YES]; 
    [UIView setAnimationDuration: movementDuration]; 
    self.view.frame = CGRectOffset(self.view.frame, 0, movement); 
    [UIView commitAnimations]; 

} 


-(void)textViewDidBeginEditing:(UITextView *)textField 

{ 

    [self animateTextField: textField up: YES]; 

} 

-(void)textViewDidEndEditing:(UITextView *)textField 

{ 

    [self animateTextField: textField up: NO]; 

} 

-(BOOL)textFieldShouldReturn:(UITextView *)theTextField 

{ 

    [theTextField resignFirstResponder]; 

    return YES; 

} 
+0

可能重複的[1] [1]:HTTP://計算器.com/questions/8784316/keyboard-hides-textfield-in-different-orientation-in-ipad – 2012-01-11 13:01:14

回答

0

檢查取向,然後再向上/向下移動通過使用該[鏈接]的

if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)// move down 
else //move up 
+0

好吧我如何設置moveup和moveDown值? – crazy2431 2012-01-09 10:47:31

+0

由於您已經設置了向下移動的值。使用相同的概念。 – fibnochi 2012-01-10 10:23:02