UIPushButton修改版

看了下UIPushButton的源代码,发现没有记录touch began的坐标点位置,导致如果在滚动视图中放置一个UIPushButton,然后拖动按钮之后按钮的click事件依然会触发。所以简单修改了一下UIPushButton的代码:


function UIPushButton:onTouch_(event)
    local name, x, y = event.name, event.x, event.y
    if name == "began" then
        self.touchBeganX = x;
        self.touchBeganY = y;
        self:_setAutoScale(UIPushButton.BIG_SCALE)
        if not self:checkTouchInSprite_(x, y) then return false end
        self.fsm_:doEvent("press")
        self:dispatchEvent({name = UIButton.PRESSED_EVENT, x = x, y = y, touchInTarget = true})
        return true
    end

    local touchInTarget = self:checkTouchInSprite_(self.touchBeganX, self.touchBeganY)

代码里只看到有记录began的坐标点,没看到有其他的处理?

明白了,刚才没看仔细,谢谢分享!

按照这个lua的编码风格变量命名应该改为self.touchBeganX_和self.touchBeganY_

self:_setAutoScale(UIPushButton.BIG_SCALE)
这个方法实现在哪?

— Begin quote from ____

引用第4楼xuhui54321于2014-10-11 21:22发表的 :
self:_setAutoScale(UIPushButton.BIG_SCALE)
这个方法实现在哪? http://www.cocoachina.com/bbs/job.php?action=topost&tid=231804&pid=1073119

— End quote


function UIPushButton:setAutoScale_(scale)
    if self.autoScale_ then
        for i,v in ipairs(self.sprite_) do
            v:setScale(scale)
        end
    end
end

楼主能不能贴上全部代码学习一下。。。