두 개의 UIButton이있는 UIViewController와 UIView를 만들었습니다.아이폰에서 서브 뷰 자동 프로그래밍하기
self.view = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
self.view.autoresizesSubviews = YES;
self.view.backgroundColor = [UIColor redColor];
UIView *view;
view = [[UIVew alloc]initWithFrame:CGRectMake(0,0,320,480)];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIButton *button1;
button.frame = CGRectMake(100,130,120,50);
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
[controller addSubview:view];
// […]
- (void)buttonAction:(id)sender
{
// I have created another view for a purpose
[view removeFromSuperview];
UIView *view_obj;
view_obj.backgroundColor = [UIColor greenColor];
view_obj.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:view_obj];
}
문제점 : I 가로로 크기가 조정되는 버튼이하지만 버튼을 누를 때 autoresized 않고 blueColor와 뷰 표시되는 뷰 방향을 변경하는 경우. 어디에 내가 redColor에 root 뷰와 greenColor.I 하위 뷰로 절반을 ShouldAutoRotate 메서드를 재정의하고이 프로젝트를 프로그래밍 방식으로 완료 할 수 있습니다. 회신 해주세요.
안녕하세요 sagar, 고마워요. 나는 노력했고 일종의 일을했습니다. 나는 또 다른 문제가 있습니다. 가로로 내비게이션 콘트롤러를 돌리면 화면에서 약간 아래로 나타납니다. 올바르게 설정하는 방법? – Cathy