Skip to content

Instantly share code, notes, and snippets.

@zii
Last active August 29, 2015 14:05
Show Gist options
  • Save zii/0a0267e27f407859522f to your computer and use it in GitHub Desktop.
Save zii/0a0267e27f407859522f to your computer and use it in GitHub Desktop.
change draging sensitivity of ccui.PageView
-- add dragging sensitive of the ccui.Pageview
function smoothpv(pageview, n)
n = n or 8
local pagen = #pageview:getPages()
for i = 0, pagen-1 do
local page = pageview:getPage(i)
page:addTouchEventListener(function(sender, e)
if e ~= ccui.TouchEventType.canceled then
return
end
local s = page:getContentSize()
local x, y = page:getPosition()
if s.width/2 > x and x > s.width/n and i > 0 then
pageview:scrollToPage(i-1)
elseif -s.width/2 < x and x < -s.width/n and i < pagen-1 then
pageview:scrollToPage(i+1)
end
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment