两种方法加入框体移动

时间:2021-09-30 18:12:24

xml中代码:

<Frame name="MyFrame" frameStrata="DIALOG" toplevel="true" enableMouse="true" movable="true" hidden="true" parent="UIParent" enableKeyboard="true" >
        <Size>
            <AbsDimension x="500" y="380"/>
        </Size>
	<Scripts>
	  <OnLoad>this:RegisterForDrag("LeftButton");</OnLoad>
	  <OnDragStart>this:StartMoving();</OnDragStart>
	  <OnDragStop>this:StopMovingOrSizing();</OnDragStop>
	  <OnMouseDown>
		this:SetClampedToScreen(true)
	  </OnMouseDown>
	</Scripts>
……
</Frame>

lua中的代码:

MyFrame:SetMovable(true)	
MyFrame:RegisterForDrag("LeftButton")

MyFrame:SetScript("OnDragStart", function()
	if arg1 == "LeftButton" then
		MyFrame:StartMoving()
	end
end)

MyFrame:SetScript("OnDragStop", function()
	MyFrame:StopMovingOrSizing()
end)

MyFrame:SetScript("OnMouseDown", function()
	MyFrame:SetClampedToScreen(true)
end)