加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 自定义UIVIew的x,y坐标

发布时间:2020-12-16 10:39:51 所属栏目:百科 来源:网络整理
导读:如何获得自定义UIVIew的x,y坐标? NSLog(@"landscape orientation and myUIView.x==%f and myUIView.y==%f",myUIView.position.x,myUIView.position.y ) 我收到以下错误 request for member 'position' in something not a structure or union 解决方法 UIVi
如何获得自定义UIVIew的x,y坐标?

NSLog(@"landscape orientation and myUIView.x==%f and myUIView.y==%f",myUIView.position.x,myUIView.position.y )

我收到以下错误

request for member 'position' in something not a structure or union

解决方法

UIView没有position属性,但它有一个框架属性( documented here),它是一个CGRect. CGRect包含原点(x / y坐标)和大小.

NSLog(@"landscape orientation and myUIView.x==%f and myUIView.y==%f",myUIView.frame.origin.x,myUIView.frame.origin.y )

框架的坐标位于父UIView(superview)的坐标系中.

编辑我最近学习了另一种打印坐标的方法:

NSLog(@"myUIView origin=%@",NSStringFromCGPoint(myUIView.frame.origin));

或整个CGRect:

NSLog(@"myUIView frame=%@",NSStringFromCGRect(myUIView.frame));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读