自定义UIVIew的x,y坐标

Bac*_*alo 3 objective-c uiview

如何获得自定义UIVIew的x,y坐标?

NSLog(@"landscape orientation and myUIView.x==%f and myUIView.y==%f",myUIView.position.x ,myUIView.position.y )
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

request for member 'position' in something not a structure or union
Run Code Online (Sandbox Code Playgroud)

pro*_*rmr 13

UIView没有position属性,但它确实有一个框架属性(此处记录),它是一个CGRect.CGRect包含原点(x/y坐标)和大小.

NSLog(@"landscape orientation and myUIView.x==%f and myUIView.y==%f",
    myUIView.frame.origin.x,
    myUIView.frame.origin.y )
Run Code Online (Sandbox Code Playgroud)

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

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

NSLog(@"myUIView origin=%@", NSStringFromCGPoint(myUIView.frame.origin));
Run Code Online (Sandbox Code Playgroud)

或整个CGRect:

NSLog(@"myUIView frame=%@", NSStringFromCGRect(myUIView.frame));
Run Code Online (Sandbox Code Playgroud)