1

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

CGPoint viewOriginX = [self.view convertPoint:self.view.frame.origin fromView:nil];

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

4

1 回答 1

9
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));

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

CGRect frame = [self.view convertRect:[self.view bounds] toView:someOtherView];
于 2013-05-15T19:05:14.680 回答