我使用下面的代码来移动textField,当我点击文本字段时,键盘不应该覆盖在文本字段上。它可以与ipad中的纵向视图一起使用。
但是当我将它旋转到PortraitUpsideDown时它不起作用。而不是textField向上移动它向下移动。执行与纵向方向相反的表现。我尝试了所有方法,但它没有工作.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 :(得分:0)
首先检查方向,然后使用
向上/向下移动if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)// move down
else //move up