2015-01-26 2 views
2

정적 인 UITableViewCell에 버튼이 있습니다. UIView를 버튼 위치에 배치하고 싶습니다.UITableViewCell의 UIButton 위치 가져 오기

방금 ​​버튼 위치를 얻으면 tableViewController의 맨 위가 아닌 tableviews 셀을 기준으로 위치가 지정됩니다. 내가 원하는 것은 tableViewController의 맨 위에서 버튼 위치를 얻는 것입니다.

예를 들어 버튼을 8px 떨어져 현재 셀의 상단에서,하지만 거리의 ViewController의 상단에서 57px, 나는 장소 57px에서의 UIView로합니다.

- (void)viewDidLoad { 
    CGPoint buttonPosition = [button convertPoint:CGPointZero fromView:self.tableView]; 
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition]; 

    CGRect rect = [myTableView rectForRowAtIndexPath:indexPath]; 

    NSLog(@"%f, %f", rect.origin.y, rect.origin.x); 

    self.infoView = [[UIView alloc] initWithFrame:CGRectMake(button.frame.origin.x, button.frame.origin.y, 220, 110)]; 
} 

nslog의 출력이 나는 또한 아이폰 가로 모드로 이동 할 때마다있는 UIView의 위치를 ​​업데이 트하려는 0

입니다 :

여기 내 코드입니다.

+0

이것은 맞춤 셀입니까? –

+0

정적 셀 –

+0

버튼 인스턴스가 있습니까? –

답변

0
CGPoint originalPoint = button.frame.origin; 
CALayer *layer = self; 
CGPoint point = originalPoint; 
while (layer.superlayer) 
{ 
    point = [layer convertPoint:point toLayer:layer.superlayer]; 
    layer = layer.superlayer; 
} 

//When you reach this code, you should have the position in the rootView 
+0

keyWIndow에서 오류가 발생합니다. –

관련 문제