ios坐标位置转换

//ios常用坐标转换来处理一些下拉框队形的按钮的位置,我以最下面两个来进行一下个人的理解,不足之处多多见谅

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

 

/*

  将当前的视图的frame 转换成到距离目标视图的距离,返回真实视图的距离

    rc值 = view.fram+rect

*/

  //view1为目标视图 self.view表示当前视图

    CGRect rect = CGRectMake(view1.frame.size.width/2, view1.frame.size.height, view1.frame.size.width, view1.frame.size.height);

       CGRect rc = [view2 convertRect:rect fromView:view1];

    view2.frame =rc;

 

  /*

     将当前的视图的frame 转换成到目标视图的距离 返回到目标位置的距离

     frame = rect -view.frame

    */

    CGRect rect = CGRectMake(200, 200, view1.frame.size.width, view1.frame.size.height);

    CGRect rc = [view2 convertRect:rect toView:view1];

    view2.frame =rc;

    NSLog(@"%@",NSStringFromCGRect(rc));

 

转载于:https://www.cnblogs.com/qitiandasheng/p/5486714.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS 高德地图 SDK 中,可以使用 `MAMapView` 对象进行地图的显示和交互。该对象提供了一些方法可以实现坐标转换屏幕像素的功能。 以下是将地图上的经纬度坐标转换为屏幕像素的示例代码: ```objective-c // 初始化一个 MAMapView 对象 MAMapView *mapView = [[MAMapView alloc] initWithFrame:self.view.bounds]; // 创建一个 CLLocationCoordinate2D 类型的坐标 CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(39.908692, 116.397477); // 将经纬度坐标转换为屏幕像素 CGPoint point = [mapView convertCoordinate:coordinate toPointToView:self.view]; NSLog(@"Screen point: %@", NSStringFromCGPoint(point)); ``` 以上代码中,`convertCoordinate:toPointToView:` 方法可以将地图上的经纬度坐标转换为在当前视图中的屏幕像素坐标。其中 `toPointToView:` 参数表示需要转换到的视图对象,这里使用 `self.view` 表示当前视图。 除了将经纬度坐标转换为屏幕像素,还可以使用 `convertPoint:toCoordinateFromView:` 方法将屏幕像素坐标转换为地图上的经纬度坐标。示例代码如下: ```objective-c // 创建一个 CGPoint 类型的屏幕像素坐标 CGPoint point = CGPointMake(100, 200); // 将屏幕像素坐标转换为地图上的经纬度坐标 CLLocationCoordinate2D coordinate = [mapView convertPoint:point toCoordinateFromView:self.view]; NSLog(@"Coordinate: %f, %f", coordinate.latitude, coordinate.longitude); ``` 以上代码中,`convertPoint:toCoordinateFromView:` 方法可以将屏幕像素坐标转换为地图上的经纬度坐标。其中 `toCoordinateFromView:` 参数表示需要转换的视图对象,这里同样使用 `self.view` 表示当前视图。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值