iOS htmlViewer scroll position

  1. 7 months ago

    Hello everyone,

    Is there a way to find the Scroll position of an htmlViewer in order to hold it, refresh Data in the html and then set the previous position again?
    Or another more efficient way?
    I have a Xojo iOS App that uses html Viewer to show live results which i refresh every 45 seconds but i want the html to show the scroll position that I am watching.

    Thank you in Advance

    Hi Sebastian,

    Yes it is possible. The HTMLViewer has a scrollView object with a scroll position.

    Using Jason King's iOSKit:

    Declare Function scrollview Lib UIKitLib selector "scrollView" (obj_id As ptr) As ptr
    
    Dim scroll as ptr = ScrollView(HTMLViewer1.Handle)
    
    Dim offset As New Foundation.NSPoint
    
    #If Target32Bit
      Declare Function ContentOffset_ Lib UIKitLib selector "contentOffset" (obj_id As ptr) As nspoint32
      Dim pt As NSPoint32 = ContentOffset_(scroll)
      offset.x = pt.x
      offset.y = pt.y
      
    #ElseIf Target64Bit
      Declare Function ContentOffset_ Lib UIKitLib selector "contentOffset" (obj_id As ptr) As nspoint64
      Dim pt As NSPoint64 = ContentOffset_(scroll)
      offset.x = pt.x
      offset.y = pt.y
    #EndIf

    offset will then have the X and Y positions of the scroll.

    After loading you will need to use the setContentOffset function to reset the position.

  2. Jérémie L

    17 May 2017 Pre-Release Testers Answer Europe (France)

    Hi Sebastian,

    Yes it is possible. The HTMLViewer has a scrollView object with a scroll position.

    Using Jason King's iOSKit:

    Declare Function scrollview Lib UIKitLib selector "scrollView" (obj_id As ptr) As ptr
    
    Dim scroll as ptr = ScrollView(HTMLViewer1.Handle)
    
    Dim offset As New Foundation.NSPoint
    
    #If Target32Bit
      Declare Function ContentOffset_ Lib UIKitLib selector "contentOffset" (obj_id As ptr) As nspoint32
      Dim pt As NSPoint32 = ContentOffset_(scroll)
      offset.x = pt.x
      offset.y = pt.y
      
    #ElseIf Target64Bit
      Declare Function ContentOffset_ Lib UIKitLib selector "contentOffset" (obj_id As ptr) As nspoint64
      Dim pt As NSPoint64 = ContentOffset_(scroll)
      offset.x = pt.x
      offset.y = pt.y
    #EndIf

    offset will then have the X and Y positions of the scroll.

    After loading you will need to use the setContentOffset function to reset the position.

  3. Jason K

    17 May 2017 Pre-Release Testers

    Jeremie just so you know you can actually make the assignments for offset to just

    offset = pt
    Or 
    Offset = ContentOffset_(scroll)

    Since Operator_Convert in NSPoint handles the assignment for you. I intended iOSKit to never require you to use the 32/64 bit structures directly and instead let the wrapper do everything for you to make it easier to use, but it works either way.

  4. Thank you Jeremie and Jason for the answers.

    The only problem is that you need to wait for the html to be loaded in order
    to set the scroll position. Do you know if there is a declare to catch load finish event for ioshtmlviewer?
    I am currently using a timer that sets scroll 10 mills after i try to load my html.

  5. Jérémie L

    18 May 2017 Pre-Release Testers Europe (France)

    You're welcome,

    Yes there is, Jason posted a Xojo project to expose the htmlViewer delegate that has events for finished loading.

    I'm sorry I don't have a link for the project file.

  6. I found it. Thank you again Jeremie.

or Sign Up to reply!