无法在textfielddidbeginediting内的方法内移动框架

时间:2015-03-24 03:08:24

标签: objective-c

我正在尝试在开始编辑时移动文本框架;通过将方法调用放入" keyboardWasShown"来攻击它。但这是推迟次优的解决方案。如何从didBeginEditing内部的方法移动文本字段?该方法被调用,但它似乎忽略了移动框架。有趣的是,第二次与commentField交互时框架正确移动。代码:

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
if ([textField isEqual:self.commentField])    {
    self.commentField.text=@"";
    [self.commentField setTextColor:[UIColor blackColor]];
    [self animateTextFieldUp:self.commentField];

}
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self animateTextFieldDown:self.commentField];
}
CGFloat KEYBOARD_HEIGHT;
- (void)keyboardWasShown:(NSNotification*)notification {
// Get the size of the keyboard.
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
KEYBOARD_HEIGHT=keyboardSize.height;
[self animateTextFieldUp:self.commentField];
}

-(void)animateTextFieldUp:(UITextField*)textField
   {


int movement = movementDistance;

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


}

0 个答案:

没有答案