UitextField resignFirstResponder 在滚动视图中不起作用

UitextField resignFirstResponder does not work in scroll view(UitextField resignFirstResponder 在滚动视图中不起作用)
本文介绍了UitextField resignFirstResponder 在滚动视图中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有 2 个函数可以 resignFirstResponder,但是当文本字段在滚动视图中时它们都不起作用

I have 2 functions to resignFirstResponder but neither of them works when the textfields are in scrollview

我的功能:

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {

        if (theTextField == textField1) {
        [textField1 resignFirstResponder];
    }
    if (theTextField == textField2) {
        [textField2 resignFirstResponder];
    }
    if (theTextField == textField3) {
        [textField3 resignFirstResponder];
    }


    return YES;

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    [textField1 resignFirstResponder];
    [textField2 resignFirstResponder];
    [textField3 resignFirstResponder];

}

我已经在 IB 中链接了滚动视图,我不知道为什么只有当我在滚动视图之外单击时它才在那里不起作用.所以它只响应视图,但是为什么?我认为 [[eventallTouches] anyObject] 响应 ANYObjects 处的 ALLtouches

I have linked the scroll view in IB, I can not find out why it does not works there only when I click outside of scrollview.so it only responds to view, but why?I thougth that [[event allTouches] anyObject] respond to ALLtouches at ANYObjects

感谢您的帮助

推荐答案

增加一个透明的视图,继承 UIControl 的大小等于你的滚动视图,不是更优雅一点吗到它的最后面,然后为这个新视图创建 IBAction?

Wouldn't it be a bit more elegant to add a transparent view that inherits UIControl with the size that equal to your scroll view to the very back of it and then just create IBAction for this new view?

这篇关于UitextField resignFirstResponder 在滚动视图中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中设置滚动视图内容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自动滚动)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延迟加载)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模拟器上运行时,使用 iOS 6.0 SDK 并为 iOS 5 Target 构建会导致 UIScrollView setMinimumZoomScale 失败) -
Create partial-screen UIPageViewController programmatically(以编程方式创建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可缩放?)