--[[ 小键盘逻辑 self.keyBoardView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIKeypad), {parentView = self, callBackParam = data, x = eventClickPos.x+70, y = 200, minNum = 0, maxNum = 100}, nil, nil); 调用的地方需要添加接口: 1、ExcuteKeyBoardBack(缓存的全部数量数字, 参数) 2、CloseKeyBoardView() 勇哥说两个界面尽量相互独立,不要用callback的方式传入 ]] local UIKeypad = UIViewClass() function UIKeypad:OnCreated() self.cacheNumStr = ""; end function UIKeypad:OnOpened(context) self.parentView = context.parentView; self.callBackParam = context.callBackParam self.minNum = context.minNum or 1; self.maxNum = context.maxNum or 999; local bottomTransform = self.Bottom.transform if context.x ~= nil and context.y ~= nil then bottomTransform:SetLocalPosition(context.x, context.y, 0) end if context.scale then bottomTransform:SetLocalScale(context.scale, context.scale, 1) else bottomTransform:SetLocalScale(1, 1, 1) end self:SetSortingLayer(true, "UITopmost", 0) end function UIKeypad:ExcuteClose() if self.parentView and self.parentView.CloseKeyBoardView then self.parentView:CloseKeyBoardView(); end end function UIKeypad:OnButtonClicked(comp) if comp == self.Button1 then self:ExcuteClickNum(1) elseif comp == self.Button2 then self:ExcuteClickNum(2) elseif comp == self.Button3 then self:ExcuteClickNum(3) elseif comp == self.Button4 then self:ExcuteClickNum(4) elseif comp == self.Button5 then self:ExcuteClickNum(5) elseif comp == self.Button6 then self:ExcuteClickNum(6) elseif comp == self.Button7 then self:ExcuteClickNum(7) elseif comp == self.Button8 then self:ExcuteClickNum(8) elseif comp == self.Button9 then self:ExcuteClickNum(9) elseif comp == self.Button10 then self:ExcuteClickNum(0) elseif comp == self.ButtonCancel then self:ExcuteClickNum(-1) elseif comp == self.ButtonConfirm then self:ExcuteClose() elseif comp == self.TipWindow then self:ExcuteClose() end end function UIKeypad:ExcuteClickNum(num) local callBackNum = 0; if num == -1 then local len = string.len(self.cacheNumStr); if len >= 2 then self.cacheNumStr = utf8.sub(self.cacheNumStr, 1, len) else self.cacheNumStr = ""; end elseif num == 0 and string.isNilOrEmpty(self.cacheNumStr) then return; else self.cacheNumStr = self.cacheNumStr .. num; end local callBackNum = tonumber(self.cacheNumStr) or 0; if callBackNum < self.minNum then if callBackNum ~= 0 then self:ResetCacheNum(tostring(self.minNum)); end callBackNum = self.minNum; elseif callBackNum > self.maxNum then callBackNum = self.maxNum; self:ResetCacheNum(tostring(callBackNum)); end if self.parentView and self.parentView.ExcuteKeyBoardBack then self.parentView:ExcuteKeyBoardBack(callBackNum, self.callBackParam); end end function UIKeypad:ResetCacheNum(numStr) self.cacheNumStr = numStr; end return UIKeypad