convertPoint to window coordinates doesn't work as I expect - uiview

I need to know the absolute position of my UILabel in the window coordinates.
This UILabel (in the code below, uil) is located inside a view at 34 x 174 y of the view coordinate system)
I see that many psay that convertPoint should be used to get the absolute values.
But after convertion I get a CGPoint that is still at 34 x 174 y.
While I expected coordinates referring to the screen window.
Could you explain to me what I am doing wrong and how to get the window coordinates of my label?
CGPoint cgp = [uil convertPoint:uil.frame.origin fromView:nil];
Thanks

The documentation for convertPoint:toView: says, "If view is nil, this method instead converts to window base coordinates." It sounds like you want that rather than fromView:.

Related

Get HTML element by position

I am using TWebBrowser in Delphi.
I need help to get an HTML element by its position.
The element I need is in a frame. Using elementFromPoint():
Document.elementFromPoint(X, Y)
I am getting the frame itself, but not what is inside of it.
I tried to get it using this:
WebBrowser.OleObject.Document.Frames
But this gives me an access error when transferring frames.
Using Document.elementFromPoint() is the correct approach. What you are not taking into account is that the HTML is parsed in a hierarchical DOM tree and elementFromPoint() is not recursive.
You are asking the browser's top-level Document to find an immediate child element at a given X,Y coordinate within the Document. In this case, that is a frame element.
A frame is an embedded window that holds another Document. You need to access the frame's Document and ask it to find a child element at the target X,Y coordinate within the frame. And so on, and so on, until you finally reach the bottom-most child.
Note that elementFromPoint() takes client coordinates that are relative to the top-left corner of the Document you are calling elementFromPoint() on. So, when you want to search a child frame's Document, you need to first subtract the frame's own top-left X,Y coordinate (within its parent Document) from the target X,Y coordinate before calling elementFromPoint() on the frame's Document.

Check if coordinate rectangle contains CLLocationCoordinate2D

I am using a special Map SDK for iOS and I am adding a custom shape to the map. The shape is always a different size and it could be a circle, square, star etc. the point being it is always dynamic whenever the app is run.
After adding this shape to the map, I can access it's property called overlayBounds which is described as: This property contains the smallest rectangle that completely encompasses the overlay.
The overlay is my shape that I'm adding to the map.
Whenever a location update is generated by CLLocationManager, I want to check and see if the most recent coordinate is inside of that overlayBounds property of the shape.
When accessing overlayBounds, it has an ne property and a sw property. Both of these are just CLLocationCoordinate2D's
So, if the overlayBounds is made up of two CLLocationCoordinate2D's and the CLLocationManager is always updating the user's location and giving me the most recent coordinate(CLLocationCoordinate2D), how can I check if that most recent coordinate is within the overlayBounds?
After doing a lot of research I have only found one potential solution to go off of which is this: https://stackoverflow.com/a/30434618/3344977
But that answer assumes that my overlayBounds property has 4 coordinates(CLLocationCoordinate2D's), when I only have 2.
Your description seems much harder then the actual question. So if I am getting this correctly your question is only to check if the point is inside the rectangle described in overlayBounds.
You have only 2 points as it is enough to define a rectangle. So NE and SW are the two points where the other two are received as (NE.x, SE.y) and (SE.x, NE.y). With this you may use the answer you linked or you may simply construct a MKMapRect where origin is NE and size is SE-NE. So in this case you may simply use MKMapRectMake and then use MKMapRectContainsPoint. BUT watch out when computing size as SE-NE might produce negative results in which cases you need to add degrees to the size. That is 180 to x (latitude) and 360 to y (longitude)...
MKMapRect rect = MKMapRectMake(NE.latitude, NE.longitude, SE.latitude-NE.latitude, SE.longitude-NE.longitude);
if(rect.width < .0) rect.width += 180.0;
if(rect.height < .0) rect.height += 360.0;
BOOL pointInside = MKMapRectContainsPoint(rect, pointOnMap);
Something like this should do the trick.
Now if you are trying to check if the point is inside the shape itself it really depends on how your shape is defined. If this is some form of analytic representation you might find some method already made for you to return the value but if not then your best shot would most likely be drawing the shape to some canvas and checking the color of canvas at the location you need to check. In any case the bigger problem here is converting the point and the rect to a Cartesian coordinate system. If that is the case then just add a comment and I will try to help you on that...

Xcode Check If Point Is in Transformed UIView

I have a UIView with a height of 100 and a width of 50. I am then rotating the view 45 degrees. After I rotate the view, then frame increase. How Can I determine If a point lies inside the view.
If I just compare the frame to the point I will get a false positives when the point is off the view but still in the frame. I want to see if the point is in the initial 50x100 rotated view.
Right Now I am getting the height of the point in relation to the view. Then I am using said height to calculate the distance from the left wall; I calculate the length to the side using the fact that is is a 45-45-90 triangle. Using this distance I am checking is the point.x is within the acceptable variance. This method is off as the point moves up and to the right.
Is there a built in function that will give a BOOL or framework. Or what am I doing wrong in my formula.

How do I find the lowest or highest point on a UIView being dragged with UIAttachmentBehavior?

Depending on where the anchorPoint is with UIAttachmentBehavior, the view can be quite rotated, so it's in more of a diamond shape than a square. In these situations, where it's rotated say 90°, how do I find what the lowest or highest point of this UIView is (in relation to the window)?
It's easy enough when the UIView is a (non-rotated) square, as I can just use CGRectGetMaxY (or min) and the x value doesn't matter, and then use convertPoint, but with the rotation the x value seems to have a real importance, as if I choose maxX, it will tell me the bottom right's point, while minX will give me the bottom left's.
I just want the lowest point that exists in the UIView. How do I get this?
EDIT: Here's some code showing how I'm attempting it currently:
CGPoint lowestPoint = CGPointMake(CGRectGetMinX(weakSelf.imageView.bounds), CGRectGetMaxY(weakSelf.imageView.bounds));
CGPoint convertedPoint = [weakSelf.imageView convertPoint:lowestPoint toView:nil];
The tracking of convertedPoint's y value completely changes depending on what I supply for the x value in lowestPoint's CGPointMake.
The view's frame is its bounding box. Normally you should be careful about using the frame of a transformed view, which is precisely what a rotated-by-UIKit-Dynamics view is. But it does give the info you are after.

How can I draw a point at my ImagevView's anchorpoint?

I am trying to achieve some effect using imageViews and I need to set the anchorpoint correctly. It is very hard without it being visible.
How would you go about showing it up on the imageview ?
The anchor point is a property specified on the layer (you will need QuartCore to access it). It is specified in the unit coordinate space of the device (both x and y goes from 0 to 1 within the bounds of the layer. You can know the coordinate of the actor point by multiplying the x value with the width and the y value with the height. To draw a point at that location you could just add a new, small layer (bounds 4x4 and corner radius 4 (to get a circle))
Be aware that changing the anchor point will change where the layer (and the view) appears on screen as the frame is calculated relative to the anchor point. To have the frame appear in the same place after the anchor point has been set you could re-set the frame (this will update the layers position so that the frame is what you expect it to be)

Resources