gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 19:51:52 25 4
gpt4 key购买 nike

如何获取自定义 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 没有位置属性,但它有一个框架属性(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(父 View )的坐标系中。

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

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

或整个 CGRect:

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

关于objective-c - 自定义 UIVIew 的 x,y 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3128524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com