UIView的CGPoints

i_r*_*aqz 1 iphone cgpoint ios

我们如何获得UIView的所有四个坐标?我以为这就是它.

CGPoint viewOriginX = [self.view convertPoint:self.view.frame.origin fromView:nil];
Run Code Online (Sandbox Code Playgroud)

但是CGPoint的右上角,左下角和右下角呢?

Noa*_*oon 8

CGRect frame = [self.view frame];
CGPoint topLeft = CGPointMake(CGRectGetMinX(frame), CGRectGetMinY(frame));
CGPoint topRight = CGPointMake(CGRectGetMaxX(frame), CGRectGetMinY(frame));
CGPoint bottomLeft = CGPointMake(CGRectGetMinX(frame), CGRectGetMaxY(frame));
CGPoint bottomRight = CGPointMake(CGRectGetMaxX(frame), CGRectGetMaxY(frame));
Run Code Online (Sandbox Code Playgroud)

如果在特定视图中需要这些坐标,则第一行应该是类似的

CGRect frame = [self.view convertRect:[self.view bounds] toView:someOtherView];
Run Code Online (Sandbox Code Playgroud)