下面是我的代码,用于在键盘启动时显示文本字段。 现在,它与代码一起工作正常。但是,给我警告可能无法响应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];
}
}
答案 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
方法,以便编译器在遇到该函数之前看到它。