获取以下代码的警告"May not respond to animetedTextField:up"



下面是我的代码,使文本字段在键盘打开时可见。现在,它与代码一起工作得很好。然而,给我警告,可能不响应animateTextField:up。有人能帮我去掉这个警告吗?

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [self animateTextField:textField up:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    [self animateTextField:textField up:NO];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
    int animatedDistance;
    int moveUpValue = textField.frame.origin.y+ textField.frame.size.height;
    UIInterfaceOrientation orientation =
    [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIInterfaceOrientationPortrait ||
        orientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        animatedDistance = 216-(460-moveUpValue-5);
    }
    else
    {
        animatedDistance = 162-(320-moveUpValue-5);
    }
    if(animatedDistance>0)
    {
        const int movementDistance = animatedDistance;
        const float movementDuration = 0.3f; 
        int movement = (up ? -movementDistance : movementDistance);
        [UIView beginAnimations: nil context: nil];
        [UIView setAnimationBeginsFromCurrentState: YES];
        [UIView setAnimationDuration: movementDuration];
        self.view.frame = CGRectOffset(self.view.frame, 0, movement);       
        [UIView commitAnimations];
    }
}

.m文件中放置一个空类别,并在@interface中声明您的方法。

@interface TheClass ()
- (void) animateTextField: (UITextField*) textField up: (BOOL) up;
@end

在@implementation .h文件中声明- (void) animateTextField: (UITextField*) textField up: (BOOL) up方法

animateTextField函数移到您的textFieldDidBeginEditing方法之上,以便编译器在到达该函数之前看到它。

相关内容

最新更新