iOS Question How to get the position of a view relative to the screen

cxbs

Active Member
Licensed User
Longtime User
hello everyone!
I want to make a long press pop-up menu
So I want to get the full screen coordinates of the long pressed view
I found some information on the Internet, but I'm not familiar with objc
I don't know how to convert to b4i code
thank you!

B4X:
UITouch* touch = [[event touchesForView:btn] anyObject];
CGPoint rootViewLocation = [touch locationInView:[FtAppDelegate shareAppDelegate].rootViewCtrl.view];

UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
CGRect rect=[bView convertRect: bView.bounds toView:window];


The above English is from translation software
 

hatzisn

Expert
Licensed User
Longtime User

I do not think that objc is needed. All you have to do is check view.Left and view.Top after the page resize event was fired in conjunction with GetLayoutValues (i am not in front of a computer but I think GetLayoutValues is the correct command). For example:

B4X:
Dim lv As LayoutValues = GetLayoutValues
'Check lv.Width in relation with view.Left and the same is valid for height, top.

Edit - Now that I read better your message you do not need the layoutvalues at all but just view.Left and view.Top after the page resize event is fired.
 
Last edited:
Upvote 0

cxbs

Active Member
Licensed User
Longtime User

Hello, hatzisn
Thank you for your reply
I use this method now
However, when multiple panels are nested, it is difficult to obtain the accurate relative position

 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Why? Left of view = ParentView.Left+NestedViewInParent.Left (and this goes on recursively for all the nested (in nested in nested) views. The same is valid for the height (height, top)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…