如何获取自定义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
答案 0 :(得分:14)
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));