- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我所有的 UiTextField 都是以编程方式创建的,所以我不能只是右键单击并将 onTab 函数拖放到 swift 文件中。
我尝试向文本字段添加手势识别器,但现在我必须双击才能触发 clickTextField()。
// make clickable
let clickName = MyTapGesture(target: self, action: #selector(ViewMain.clickTextField(_:)))
clickName.count_of_selection = String(i)
self.finishName[i].addGestureRecognizer(clickName)
我怎样才能让它一键工作。也许是一种不同的方法?
最佳答案
UITextField
有一个点击手势。您需要使用它的委托(delegate)方法:
func textFieldShouldBeginEditing(_ textField: UITextField)
func textFieldDidEndEditing(_ textField: UITextField)
func textFieldShouldEndEditing(_ textField: UITextField)
func textFieldDidBeginEditing(_ textField: UITextField)
func textFielShouldClear(_ textField: UITextField)
func textFielShouldReturn(_ textField: UITextField)
不要忘记
yourTextField.delegate = self
在你为你的 vc 创建一个扩展之后:
extension ViewController: UITextFieldDelegate {
// here you add the necessary delegate methods for your textFields
}
注意:您不需要实现每个方法。只使用你需要的那个。更多详细信息,请访问 AppleDeleveloper .
关于swift - 将 TapGestureRecognizer 添加到 TextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53400439/
当我点击第一个 ViewController 中的 UIImageView 时,我正在调用另一个类中的函数: let tapGestureRecognizer = UITapGestureRecogn
所以我有一个自定义 View ,我在 View Controller 的 for 循环中创建了许多 View 。在创建它们时,我对每个它们调用此方法: -(void)setUpStuff{ /
您好,我没有卡片可以用来解决这个问题。我们开始吧。 我有这五个 imageview,这是第一个 imageview 的声明,但基本上它们有相同的声明 @IBOutlet weak var first
嗨,在 viewDidLoad 的主 WiewController 中,我设置了一个 UIGestureRecognizer *recognizer = [[UITapGestureRecognize
我有一个问题。我创建了一个示例项目来解决它,但没有成功。我创建了一个负边距的按钮,位于导航栏的中间。水龙头仅适用于下部。 MainPage.xaml:
我正在 iOS 6.1 上为 iPad 开发一个应用程序。我的 CALayer 和 TapGestureRecognizer 有问题。 我有 7 个 CALayers 形成彩虹(每一层都是一种颜色)。
在我的应用程序中,我有一张图片和一个 UITextView . 我创建了一个 UITapGestureRecognizer对于这两种 View ,但问题是无论我在屏幕上单击什么位置,只有与 UITex
我对 UITableViewCell 进行了子类化。我尝试添加手势识别器,但点击它时没有任何反应。 class MessagesTableViewCell: UITableViewCell {
谁能帮我解决这个错误?不确定它要求什么... TapGestureRecognizer Syntax override func viewDidLoad() { super.viewD
我正在尝试使用 Firebase 构建一个聊天应用程序。我正在尝试实现点击手势,以便在键盘打开时关闭键盘。不幸的是,当您点击屏幕时没有任何反应。我尝试了不同的东西,结果相同。如果有人知道它不起作用的原
这段代码的目的是将 UIView 动画到屏幕上的某个位置。不幸的是,它根本没有注册水龙头。我是否应该将委托(delegate)设置为我的设置中的某些内容?任何帮助将不胜感激! public class
我已经设置了一个点击手势识别器并将识别器添加到 uibutton。该按钮有一个背景图像。当我点击按钮时,它根本不突出显示,我唯一能做的就是更改它的 alpha 值。 UITapGestureReco
我想添加一个 *UITapGestureRecognize*r 到我的 UITextView,因为我想关闭 TextView 所在的“弹出窗口”。所以我想要,当点击 T*extView* 时,将调用
我正在尝试实现 TapGestureRecognizer,它将在 ViewModel (xaml.cs) 中调用,而不是在 View 类中...... 这是 xaml 文件中的示例代码:(IrrigN
我有一个 XF 应用程序,其中定义了以下 Collection View 。第二个标签有一个 TapGestureRecognizer,当我点击标签(在 Android 上尝试这个)时,它不会在模型中
我有一个 XF 应用程序,其中定义了以下 Collection View 。第二个标签有一个 TapGestureRecognizer,当我点击标签(在 Android 上尝试这个)时,它不会在模型中
所以我有一个像照片库一样的应用程序,我正在实现用户删除图像的能力。这是设置:我有 9 个 UIImageView、imageView、imageView2 等。我还有一个“编辑”按钮和一个 tapGe
我正在 swift 3.0 中开发一个项目,我有 UIViewController 来填充一些文本字段。因此,我使用 TableView 作为下拉菜单,一旦选择一行,它将被分配给 UILabel。此外
我正在 swift 3.0 中开发一个项目,我有 UIViewController 来填充一些文本字段。因此,我使用 TableView 作为下拉菜单,一旦选择一行,它将被分配给 UILabel。此外
我有一个 UIToolbarButton,它有一个 UIButton 来保存图像。现在,当我点击这个 UIToolbarButton 时,我想在当前 View 中打开另一个 View 。 我的代码:
我是一名优秀的程序员,十分优秀!