如何查找键盘是否覆盖控件
How to find if the keyboard is covering a control
我有一个代码可以在激活键盘时移动一组控件。但我只希望它 运行 当键盘覆盖激活键盘的控件时。我正在使用下面的代码,但它无法正确确定控件何时被键盘隐藏。
堆栈脚本
lStackSize,lStackHeight
global gBottom
on openstack
set the fullscreenmode of me to "exactFit"
put the loc of group "controls" into lStackLoc
put the effective working screenRect into lStackSize
put item 4 of lStackSize - item 2 of lStackSize into lStackHeight
end openstack
-------------------------------
on keyboardactivated
answer "control bottom" && gbottom
put the effective working screenRect into tStackSize
set itemdel to comma
put item 4 of tStackSize - item 2 of tStackSize into tStackHeight
answer "tStackHeight" && tStackHeight & return & "gbottom" && gBottom
if gbottom<tStackHeight then
answer "control Visible"
else
answer"control Hidden"
put gbottom - tStackHeight into tYMove
put item 2 of lStackLoc - tYMove into tNewLocY
put item 1 of lStackLoc & "," & tNewLocY into tStackLoc
move group "controls" to tStackLoc
end if
end keyboardactivated
---------------------------
on keyboardDeactivated
move group "controls" to lStackLoc
end keyboardDeactivated
控制脚本
global gBottom
on openfield
put the bottom of me into gBottom
end openfield
有效screenRect是指屏幕上实际可用的矩形(可见的屏幕上真正被应用使用的部分)。工作 screenRect 是屏幕的一部分,例如没有被使用。状态栏。
put the effective working screenRect into myRect
if the topleft of control x is not within myRect \
or the bottomright of control x is not within myRect then
// control x is outside the visible part of the window
end if
The working screenRect
可能就足够了,但文档在讨论 effective
时特别提到了键盘
我有一个代码可以在激活键盘时移动一组控件。但我只希望它 运行 当键盘覆盖激活键盘的控件时。我正在使用下面的代码,但它无法正确确定控件何时被键盘隐藏。
堆栈脚本
lStackSize,lStackHeight
global gBottom
on openstack
set the fullscreenmode of me to "exactFit"
put the loc of group "controls" into lStackLoc
put the effective working screenRect into lStackSize
put item 4 of lStackSize - item 2 of lStackSize into lStackHeight
end openstack
-------------------------------
on keyboardactivated
answer "control bottom" && gbottom
put the effective working screenRect into tStackSize
set itemdel to comma
put item 4 of tStackSize - item 2 of tStackSize into tStackHeight
answer "tStackHeight" && tStackHeight & return & "gbottom" && gBottom
if gbottom<tStackHeight then
answer "control Visible"
else
answer"control Hidden"
put gbottom - tStackHeight into tYMove
put item 2 of lStackLoc - tYMove into tNewLocY
put item 1 of lStackLoc & "," & tNewLocY into tStackLoc
move group "controls" to tStackLoc
end if
end keyboardactivated
---------------------------
on keyboardDeactivated
move group "controls" to lStackLoc
end keyboardDeactivated
控制脚本
global gBottom
on openfield
put the bottom of me into gBottom
end openfield
有效screenRect是指屏幕上实际可用的矩形(可见的屏幕上真正被应用使用的部分)。工作 screenRect 是屏幕的一部分,例如没有被使用。状态栏。
put the effective working screenRect into myRect
if the topleft of control x is not within myRect \
or the bottomright of control x is not within myRect then
// control x is outside the visible part of the window
end if
The working screenRect
可能就足够了,但文档在讨论 effective