2011-09-19 4 views
0

보기에 일부 하위보기를 추가 한 다음 해당보기를 배치하여 모든 하위보기가 "따라 가게"할 수 있습니까? 하위 뷰를위한 컨테이너 역할을하므로 뷰의 위치를 ​​변경하고 뷰 내의 모든 하위 뷰의 위치를 ​​재조정하지 않아도됩니다.Objective-C -보기 내에서보기의 위치 지정

저는 IB가 아니라 프로그래밍 방식으로이 솔루션을 찾고 있습니다.

답변

2

UIView을 부모보기로 사용하면 모든 하위보기가 수행됩니다.

UIView *parentView = [[UIView alloc] initWithFrame:self.view.bounds] 
[self.view addSubview:parentView]; // Assuming self is a ViewController 
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
btn1.frame = CGRectMake(10, 10, 120, 44); 
[parentView addSubview:btn1]; 

// Sets a new position with the same view size 
parentView.frame = CGRectMake(50, 100, self.view.bounds.size.width, self.view.bounds.size.height); 

이제 parentView의 새 프레임을 설정할 때. btn1은 parentView를 기준으로 위치가 지정됩니다.

나는 당신의 질문을 올바르게 이해하기를 바랍니다.

편집 : 추가 된

코멘트