문제

How do we get all four coordinates of a UIView? I thought this would be it.

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

But what about CGPoint of the top right, bottom left and bottom right points?

도움이 되었습니까?

해결책

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

If you need those coordinates in a particular view, the first line should be something like

CGRect frame = [self.view convertRect:[self.view bounds] toView:someOtherView];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top