iOS Question Get real position of view

webhost.company

Active Member
Licensed User
Longtime User
Hello
I have a Button in Panel and this panel is inside other panel
I need to get top and left of button in main panel
Or actually GetRelativeTopLeft
 

tufanv

Expert
Licensed User
Longtime User
Hello
I have a Button in Panel and this panel is inside other panel
I need to get top and left of button in main panel
Or actually GetRelativeTopLeft

if the button is a child of panel2 and panel 2 is the child of panel 1 you can get the top and left value of the button according to main page with stg like :

panel1.top+panel2.top+button1.top which means if panel1's top is 40 and inside panel 1 , panel2's top is 50 and inside panel 2 , button1's top is 20 then , button1's top according to main view is 110.
 
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
Please help me
NoBody?

Download OBJS.bas attached

and use this method.

B4X:
OBJC.PositionInView(View As View,Parent As View) As Point

it is returning the X and Y coordinates of the center of the view in relation to the parent.

So if you need left and top it would be.

Left=OBJC.PositionInView(View As View,Parent As View).X - (View.width/2)

Top=OBJC.PositionInView(View As View,Parent As View).Y - (View.Height/2)
 

Attachments

  • OBJC.bas
    4.4 KB · Views: 202
Last edited:
Upvote 0

webhost.company

Active Member
Licensed User
Longtime User
if the button is a child of panel2 and panel 2 is the child of panel 1 you can get the top and left value of the button according to main page with stg like :

panel1.top+panel2.top+button1.top which means if panel1's top is 40 and inside panel 1 , panel2's top is 50 and inside panel 2 , button1's top is 20 then , button1's top according to main view is 110.
This solution is best and simple Thanks
 
Upvote 0
Top