以下代码获取警告“可能无法响应animetedTextField:up”

时间:2011-12-03 14:03:50

标签: iphone ios xcode

下面是我的代码,用于在键盘启动时显示文本字段。 现在,它与代码一起工作正常。但是,给我警告可能无法响应animateTextField:up。 any1请帮我删除此警告?

- (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];
    }
}

2 个答案:

答案 0 :(得分:2)

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

@interface TheClass ()

- (void) animateTextField: (UITextField*) textField up: (BOOL) up;

@end

答案 1 :(得分:1)

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

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