美文网首页
iOS中的坐标转换

iOS中的坐标转换

作者: hard_coder | 来源:发表于2018-05-31 14:33 被阅读0次

    //    1.convertRect的使用

    //    1  [A convertRect:B.frame  toView:C];

    //    计算A上的B视图在C中的位置CGRect

    //    2  [A convertRect:B.frame  fromView:C];

    //    计算C上的B视图在A中的位置CGRect

    //    2.convertPoint的使用

    //    1  [A convertPoint:B.center toView:C];

    //    计算A上的B视图在C中的位置CGPoint

    //    2  [A convertPoint:B.center fromView:C];

    //    计算C上的B视图在A中的位置CGPoint

    - (void)viewDidLoad {

    //    1.convertRect的使用

    //    1  [A convertRect:B.frame  toView:C];

    //    计算A上的B视图在C中的位置CGRect

    //    2  [A convertRect:B.frame  fromView:C];

    //    计算C上的B视图在A中的位置CGRect

    //    2.convertPoint的使用

    //    1  [A convertPoint:B.center toView:C];

    //    计算A上的B视图在C中的位置CGPoint

    //    2  [A convertPoint:B.center fromView:C];

    //    计算C上的B视图在A中的位置CGPoint

        [super viewDidLoad];

        UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

        redView.backgroundColor = [UIColor redColor];

        [self.viewaddSubview:redView];

        UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 30, 30)];

        blueView.backgroundColor = [UIColor blueColor];

        [self.viewaddSubview:blueView];

        //[A convertPoint:B.center toView:C];

        //    计算A上的B视图在C中的位置CGPoint

        CGPointconverPoint = [self.viewconvertPoint:blueView.frame.origintoView:redView];

        NSLog(@"%f,%f",converPoint.x, converPoint.y);

        //    2  [A convertPoint:B.center fromView:C];

        //    计算C上的B视图在A中的位置CGPoint

        CGPointconverFromPoint = [redViewconvertPoint:blueView.frame.originfromView:self.view];

        NSLog(@"%f,%f",converFromPoint.x,converFromPoint.y);

        //    1  [A convertRect:B.frame  toView:C];

        //    计算A上的B视图在C中的位置CGRect

        CGRectconverToRect = [self.viewconvertRect:blueView.frametoView:redView];

        NSLog(@"%f,%f,%f,%f",converToRect.origin.x,converToRect.origin.y,converToRect.size.width,converToRect.size.height);

        // [A convertPoint:B.center fromView:C];

        //    计算C上的B视图在A中的位置CGPoint

        CGRectconverFromRect = [redViewconvertRect:blueView.framefromView:self.view];

        NSLog(@"%f,%f,%f,%f",converFromRect.origin.x,converFromRect.origin.y,converFromRect.size.width,converFromRect.size.height);

    }

    相关文章

      网友评论

          本文标题:iOS中的坐标转换

          本文链接:https://www.haomeiwen.com/subject/pvuqsftx.html