iOS中视图坐标系的转换主要用到UIView的四个API:
坐标系转换的实质是: 更改坐标系的原点.
- (CGPoint)convertPoint:(CGPoint)point toView:(nullable UIView *)view;
- (CGPoint)convertPoint:(CGPoint)point fromView:(nullable UIView *)view;
- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;
- (CGRect)convertRect:(CGRect)rect fromView:(nullable UIView *)view;
代码:
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)UIView *redView;
@property(nonatomic,strong)UIView *blueView;
@property(nonatomic,strong)UIView *yellowView;
@property(nonatomic,strong)UIView *orangeView;
@end
@implementation