UIView的CGPoints

时间:2013-05-15 19:02:38

标签: iphone ios cgpoint

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

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

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

1 个答案:

答案 0 :(得分:7)

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];