ios - 将 UITextField 委托(delegate)设置为所有 UITextField 并为少数文本字段设置 View 动画

标签 ios objective-c cocoa-touch uitextfield

我有 13 个文本字段。我只想为 4 个文本字段设置 View 动画,这些文本字段将显示在底部

这是我的代码:

if (textField.editing != ((_GET_companyname)||(_GET_firstname)||(_GET_middlename)||(_GET_lastname)||(_GET_companyurl)||(_GET_streetaddress)||(_GET_postbox)||(_GET_code)||(_GET_phonenum)))
{
    NSLog(@"Entered in condition");
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        //Keyboard becomes visible
        [UIView beginAnimations:nil context:NULL];
        // [UIView setAnimationDuration:0.25];
        self.view.frame = CGRectMake(0,-200,self.view.frame.size.width,self.view.frame.size.height);
        [UIView commitAnimations];
    }
}
else
{
    NSLog(@"Entered else Part");
}

我需要将以下内容设置为所有 14 个文本字段

-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}

最佳答案

根据您的判断,如果“_GET_companyname”是 UITextField 的 IBOutlet。

那么你应该在下面写这样的东西

if ((textField != _GET_companyname)&&(textField != _GET_firstname)) // etc
{
    NSLog(@"Entered in condition");
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        //Keyboard becomes visible
        [UIView beginAnimations:nil context:NULL];
        // [UIView setAnimationDuration:0.25];
        self.view.frame = CGRectMake(0,-200,self.view.frame.size.width,self.view.frame.size.height);
        [UIView commitAnimations];
    }
}
else
{
    NSLog(@"Entered else Part");
}

编辑 :- 也不是检查 (!=)。你应该检查 (==) 几个 UITextFields。这样会更好。

关于ios - 将 UITextField 委托(delegate)设置为所有 UITextField 并为少数文本字段设置 View 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35915142/

相关文章:

iphone - NSLocalizedString显示键值

ios - Copy Bundle Resources 构建阶段在 xcode 6 中包含此目标的 Info.plist 文件 'Info.plist'?

ios - 在UIView的边缘添加阴影(内图)

ios - 方法泄漏中的对象

ios - 在 Google map 上显示当前位置

ios - 位置标记不显示 Swift 4

ios - 如何在运行时 Objective-C 中重写/混合私有(private)类的方法?

objective-c - 如何在Objective-C中将字节数组转换为图像

iOS:从主屏幕上的书签启动自定义应用程序

ios - 使用 NSURLSession 发送 POST 请求