2014-11-09 4 views
0

Charles B는 LiveCode를 사용하는 Android의 네이티브 스크롤러에 대한 흥미로운 대안을 게시했습니다. 그의 코드는 여기에서 찾을 수 있습니다 : Scrolling in iphone and android devices in LiveCode (이 코드의 하단에 코드를 재현합니다)기본이 아닌 Android scroller (라이브 코드)에 관성 추가

정말 작동합니다. 그러나 관성은 없습니다. 즉, 손가락을 떼면 스크롤이 트랙에서 멈 춥니 다. 그의 코드를 변경하면 관성 스크롤이 제공 될지 궁금합니다. 아마도 mouseRelease 또는 mouseUp 핸들러에 타이머를 추가했을 것입니다.

LiveCode에서 제공하는 공식 메서드는 아닙니다 ("기본"scroller가 아닙니다). 확실히 구현하기가 쉬우 며 사실 실제로 나를 위해 작동 한 첫 번째 예제 코드입니다. 제공된 텍스트의 끝까지 계속 스크롤합니다. 관성 스크롤을 추가 할 수 있다면 정말 좋을 것입니다.

감사합니다,

베리

local allowMove 
 

 
on mouseDown 
 
    put mouseH(),mouseV() into allowMove 
 
end mouseDown 
 

 
on mouseMove X,Y 
 
    if allowMove is not empty then 
 
     lock screen 
 
     if the hScrollbar of me then 
 
     set the hScroll of me to the hScroll of me + (item 1 of allowMove-X) 
 
     end if 
 
     if the vScrollbar of me then 
 
     set the vScroll of me to the vScroll of me + (item 2 of allowMove-Y) 
 
     end if 
 
     put X into item 1 of allowMove 
 
     put Y into item 2 of allowMove 
 
     unlock screen 
 
    end if 
 
end mouseMove 
 

 
on mouseUp 
 
    put empty into allowMove 
 
end mouseUp 
 

 
on mouseRelease 
 
    mouseUp 
 
end mouseRelease

답변

0

관성 유형 효과는 모르기 때문에 mouseUp 핸들러에서 약간의 반복 루프를 달성 할 수있다. 모르기 때문에 mouseUp에 기본적으로

local allowMove, sScrollPos 

on mouseDown 
    put mouseH(),mouseV() into allowMove 
    put the vScroll of me into sScrollPos 
end mouseDown 

on mouseMove X,Y 
    if allowMove is not empty then 
     lock screen 
     if the hScrollbar of me then 
      set the hScroll of me to the hScroll of me + (item 1 of allowMove-X) 
     end if 
     if the vScrollbar of me then 
      set the vScroll of me to the vScroll of me + (item 2 of allowMove-Y) 
     end if 
     put X into item 1 of allowMove 
     put Y into item 2 of allowMove 
     unlock screen 
    end if 
end mouseMove 

on mouseUp 

    put the vScroll of me into tVscroll 

    if tVscroll > sScrollPos then 
     put "down" 
     repeat with x = 1 to 20 
     set the vScroll of me to the vScroll of me + (20-x) 
     end repeat 
    end if 
    if tVscroll < sScrollPos then 
     put "up" 
     repeat with x = 1 to 20 
     set the vScroll of me to the vScroll of me - (20-x) 
     end repeat 
    end if 
     if tVscroll = sScrollPos then 
     put "same" 
    end if 

    put empty into allowMove 
end mouseUp 

on mouseRelease 
    mouseUp 
end mouseRelease 

는, 필드의 vScroll가 그 vScorll로 설정되고 +/- 혹시 .. 나 또한 당신을 알려줍니다 디버깅 약간의 다양한 반복 루프에 정의 된 가치를 추가 감산 스크롤이 위, 아래 또는 동일하게 유지됩니다.

반복 루프의 값을 변경하여 더/덜 드라마틱 한 관성 효과를 줄 수 있습니다.

관련 문제