所以我到处检查过,很难搞清楚这一点。我正在使用RedPotion在RubyMotion中编写应用程序,但在大多数情况下,我需要的帮助是使用Ruby。该应用程序几乎是一个图书应用程序,所以我试图弄清楚如何正确存储文本。基本上,我每行有一定数量的字符,我只能在屏幕上使用17行。一旦填满,我希望存储文本的其余部分以使用相同的方法在页面翻转时显示在屏幕上的下一组。然后,如果用户向后滑动,则该文本也会返回。我试过阵列,哈希。方法不同。在这个问题上已经疯狂了大约3周。任何人都可以帮助使用ruby方法或调整我的工作吗?
def on_load
@texts = [
"In the beginning of God's creation of the heavens and the earth.\nNow the earth was
astonishingly empty, and darkness was on the face of the deep, and the spirit of God was
hovering over the face of the water.\nAnd God said, 'Let there be light,' and there was light.
\nAnd God saw the light that it was good, and God separated between the light and between the darkness.
\nAnd God called the light day, and the darkness He called night, and it was evening and it was morning,
one day.\nAnd God said, 'Let there be an expanse in the midst of the water, and let it be a separation
between water and water.'"
]
@recycle = [ @texts[ 0 ] ]
@page_idx = 0
@header = append!( UIImageView, :header )
@text_view = append!( UITextView, :text_view )
text_view( @texts[ 0 ] )
@text_view.on(:swipe_right) do |sender|
recycle_text_forward( @recycle[ -1 ] )
end
@text_view.on(:swipe_left) do |sender|
recycle_text_back( @recycle[ @page_idx ] )
end
end
def text_view( text )
page_words = text.split( ' ' )
number_of_lines_idx = 17
each_line_chars = 27
chars = ""
setter = ""
idx = 0
all_idx = page_words.length - 1
@text_view.text = ""
while number_of_lines_idx != 0
until chars.length >= each_line_chars
break if page_words[ idx ] == nil
chars << page_words[ idx ] + " "
chars << "\n" if chars.length >= each_line_chars
idx += 1
end
break if page_words[ idx ] == nil
number_of_lines_idx -= 1
if number_of_lines_idx == 0
@recycle << page_words[ idx..all_idx ]
@page_idx = @recycle.length - 2
end
setter = chars
chars = ""
@text_view.text += setter
end
end
def recycle_text_forward( text )
text_view( text.join( ' ' ) )
end
def recycle_text_back( text )
text_view( text )
end
答案 0 :(得分:1)
我不确定我是否正确理解了这个问题,但这是我的建议:
00007FFD5C180B80 sub rsp,28h
00007FFD5C180B84 movsd xmm0,mmword ptr [7FFD5C180BA0h]
00007FFD5C180B8C call 00007FFDBBEC1C30
00007FFD5C180B91 addsd xmm0,mmword ptr [7FFD5C180BA8h]
00007FFD5C180B99 add rsp,28h
00007FFD5C180B9D ret
我相信,这将是进一步调整的良好开端。