omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Can I get the position of scrollbar in ui module?

    Pythonista
    4
    30
    10663
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User last edited by A Former User

      In js https://stackoverflow.com/questions/2481350/how-to-get-scrollbar-position-with-javascript

      mikael 1 Reply Last reply Reply Quote 0
      • mikael
        mikael @Guest last edited by

        @lpl, yes, check ui.ScrollView.content_offset.

        ? 1 Reply Last reply Reply Quote 1
        • ?
          A Former User @mikael last edited by

          @mikael And I need to set an action for it. Like preloading a book on web, when I scroll down, I check the position of scrollbar. And if I almost finish one page, I would preload the next page. Can I make that?

          mikael 1 Reply Last reply Reply Quote 0
          • mikael
            mikael @Guest last edited by

            @lpl, ScrollView has a content_size attribute that you should set to the size of the content already displayed.

            Then there’s ScrollView.delegate where you can define a scrollview_did_scroll method to react every time there’s scrolling. In that method you should compare scroll_offset y value + ScrollView.height to see if you are close to the content_size height value. If yes, add more content below existing content, and increase the content_size accordingly.

            ? 1 Reply Last reply Reply Quote 0
            • ?
              A Former User @mikael last edited by

              @mikael It is so strange since I can't change the content just like ScrollView.text. Must I use subview to show texts in ScrollView?

              mikael 1 Reply Last reply Reply Quote 0
              • mikael
                mikael @Guest last edited by

                @lpl, yes. You can either use one that you grow by adding more text, or add separate pages as more views.

                If your content is all text, you could of course use a TextView (with editable=False), but then you would need to use objc to access the scrolling logic.

                ? 1 Reply Last reply Reply Quote 0
                • ?
                  A Former User @mikael last edited by

                  @mikael I think maybe I can set Textviews as subviews of a Scrollview. But there is another problem. I shouldn't allow the scrollbars in Textviews to show out. So I need to adjust the size of Textview to different length of the text. Can I make it? It sounds so difficult.....

                  mikael 1 Reply Last reply Reply Quote 0
                  • mikael
                    mikael @Guest last edited by

                    @lpl, how about you use Labels with number_of_lines set to 0?

                    ? 2 Replies Last reply Reply Quote 0
                    • ?
                      A Former User @mikael last edited by A Former User

                      There is another problem. We should pre-set some labels and then we find one label is out of the screen(can't be seen by users), we move the label to the end of the lable lists or to the beginning of them. But we need to know whether the scrollbar is coming up or coming down. How to get this attribute?

                      1 Reply Last reply Reply Quote 0
                      • ?
                        A Former User last edited by

                        I found a way to check that. By using a value to record the old position and compare the old with the new one.

                        1 Reply Last reply Reply Quote 0
                        • ?
                          A Former User @mikael last edited by

                          @mikael But another problem. The text could be very very long. But the content size of the Scrollview is limited (max=9999). What can I do to make it unlimited?

                          mikael 1 Reply Last reply Reply Quote 0
                          • mikael
                            mikael @Guest last edited by

                            @lpl, maybe use reverse logic to adding new content. If you are down far enough, remove content from the beginning, move the remaining labels up and adjust scroll_offset so that this is not visible to user.

                            Then you need to implement the ”add content to top” logic as well.

                            Might be a performance problem there, but worth trying.

                            ? 1 Reply Last reply Reply Quote 0
                            • ?
                              A Former User @mikael last edited by

                              @mikael said:

                              @lpl, maybe use reverse logic to adding new content. If you are down far enough, remove content from the beginning, move the remaining labels up and adjust scroll_offset so that this is not visible to user.

                              Then you need to implement the ”add content to top” logic as well.

                              Might be a performance problem there, but worth trying.

                              I have made this. But the content size of a scrollview is limited. So if I have a long text, then I can't finish the text by using one scrollview.

                              mikael 1 Reply Last reply Reply Quote 0
                              • mikael
                                mikael @Guest last edited by

                                @lpl, I think I understood. The idea was to not let the content grow beyond a specific limit, by removing content from the start and shifting the scroll position back up again, equal to the height of the removed content, thus creating the illusion of an infinite scroll with a constant amount of content.

                                You said you had implemented this. What went wrong?

                                ? 1 Reply Last reply Reply Quote 0
                                • ?
                                  A Former User @mikael last edited by A Former User

                                  @mikael Sorry, my English is not good. I mean I have made like 8 labels move up or down when I scrolled the scrollbar. But content size of the scrollview( http://omz-software.com/pythonista/docs/ios/ui.html#ui.ScrollView.content_size) is limited. This means the Scrollview is not infinite.

                                  mikael 1 Reply Last reply Reply Quote 0
                                  • mikael
                                    mikael @Guest last edited by

                                    @lpl, please re-read my previous post. Note how we would NOT keep scrolling down, just making it look like it, thus no problem with a finite ScrollView.

                                    ? 1 Reply Last reply Reply Quote 0
                                    • ?
                                      A Former User @mikael last edited by

                                      @mikael I just find a way to make an unlimited content_size. By changing the size in the code.

                                      1 Reply Last reply Reply Quote 0
                                      • JonB
                                        JonB last edited by

                                        I wonder if you'd rather use TableView instead of scrollview?

                                        i dont think scrollview has a contentsize limit -- but if you are adding labels with text you might certainly reach a memory limit if you have 1000's of subviews!

                                        TableView lets you be much more memory efficient, because the tableview cells are only created on demand.

                                        ? 1 Reply Last reply Reply Quote 0
                                        • ?
                                          A Former User @JonB last edited by

                                          @JonB We can break down the limitation in the code. And we can use several subviews. When we scroll, if one subview is hidden(can't be seen by users), then we can move the subview from the top side to the other side. So we don't need many subviews.

                                          1 Reply Last reply Reply Quote 0
                                          • JonB
                                            JonB last edited by

                                            That is what tableview does for you already, plus you don't have to manage where the subviews go, just the order and number.

                                            ? 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors