iOS Question Absolute position of view

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code:
B4X:
Sub GetPageLeftAndTop(v As View) As Float()
   Dim tl(2) As Float
   Do While GetType(v) <> "B4IMainView"
     Dim no As NativeObject = v
     tl(0) = tl(0) + v.Left
     tl(1) = tl(1) + v.Top
     v = no.GetField("superview")
   Loop
   Return tl
End Sub

B4X:
Dim LeftTop() As Float = GetPageLeftAndTop(Button1)
Log($"Left: ${LeftTop(0)} Top: ${LeftTop(1)}"$)
 
Upvote 0
Top