1
我有一個點在子UIView
內。我想找到CGPoint
相對於子視圖的父母UIView
的位置。我如何得到它?獲取CGPoint(位於子視圖內)的位置,W.R.T的父視圖 - ObjectiveC
我有一個點在子UIView
內。我想找到CGPoint
相對於子視圖的父母UIView
的位置。我如何得到它?獲取CGPoint(位於子視圖內)的位置,W.R.T的父視圖 - ObjectiveC
CGPoint pointInSuperview = [superview convertPoint:pointInSubview fromView:subView];
實施例:
UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
[self.view addSubview:subView];
CGPoint pointInSubview = CGPointMake(20, 20);
CGPoint pointInSuperview = [self.view convertPoint:pointInSubview fromView:subView];
NSLog(@"%@", NSStringFromCGPoint(pointInSuperview));
打印出{70, 70}
到控制檯
非常感謝。 –
一樣簡單從父視圖添加原點到座標點。 –