在ScrollView中找到相对于屏幕的TextField坐标 [英] Find Coordinates of TextField in ScrollView Relative to Screen
本文介绍了在ScrollView中找到相对于屏幕的TextField坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 UIScrollView
中有大量的 UITextField
,我想检查相对于屏幕的 UITextField
,在 textFieldDidBeginEditing
委托方法中,并且仅当键盘将隐藏 UITextField
时,才向上移动屏幕.
I have a large number of UITextField
inside UIScrollView
, I want to check the coordinate of
UITextField
relative to the screen, in the textFieldDidBeginEditing
delegate method and move up the screen only if the keyboard will hide the UITextField
.
推荐答案
您可以获得文本字段的绝对位置,如下所示:
You can get the absolute position of your text field like below:
CGRect absoluteframe = [mytextfield convertRect:mytextfield.frame toView:[UIApplication sharedApplication].keyWindow];
然后使用它来测试它是否低于某个特定位置(例如键盘启动的位置),然后相应地滚动滚动视图.
then use that to test if it goes below some specific position (e.g. where the keyboard starts) and then scroll the scrollview accordingly.
这篇关于在ScrollView中找到相对于屏幕的TextField坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文