X, y coordinates of custom UIVIew

How do you get the x, y coordinates of a custom UIVIew?

NSLog(@"landscape orientation and myUIView.x==%f and myUIView.y==%f",myUIView.position.x ,myUIView.position.y )

I get the following error

request for member 'position' in something not a structure or union
+3
source share
1 answer

The UIView does not have a position property, but has a frame property ( described here ), which is a CGRect. CGRect contains the origin (x / y) and size.

NSLog(@"landscape orientation and myUIView.x==%f and myUIView.y==%f",
    myUIView.frame.origin.x,
    myUIView.frame.origin.y )

The frame coordinates are in the coordinate system of the parent UIView (supervision).

EDIT I recently learned another way to print coordinates:

NSLog(@"myUIView origin=%@", NSStringFromCGPoint(myUIView.frame.origin));

or the whole CGRect:

NSLog(@"myUIView frame=%@", NSStringFromCGRect(myUIView.frame));
+14
source

Source: https://habr.com/ru/post/1751997/


All Articles