2010-05-20 4 views
0

두 개의 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 메서드를 재정의하고이 프로젝트를 프로그래밍 방식으로 완료 할 수 있습니다. 회신 해주세요.

답변

-1

this 질문을 찾으십시오.

또는

this question에서 코드를 다음을 참조하십시오.

인터페이스 빌더에서
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {  
    UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; 
    if (interfaceOrientation == UIInterfaceOrientationPortrait 
     || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     button1.frame = CGRectMake(100, 33, 226, 275); 
     button2.frame = CGRectMake(440, 33, 226, 275); 
     button3.frame = CGRectMake(100, 360, 226, 275); 
     button4.frame = CGRectMake(440, 360, 226, 275); 
     button5.frame = CGRectMake(100, 693, 226, 275); 
     button6.frame = CGRectMake(440, 693, 226, 275); 
    } 
    else 
    { 
     button1.frame = CGRectMake(100, 50, 226, 275); 
     button2.frame = CGRectMake(400, 50, 226, 275); 
     button3.frame = CGRectMake(700, 50, 226, 275); 
     button4.frame = CGRectMake(100, 400, 226, 275); 
     button5.frame = CGRectMake(400, 400, 226, 275); 
     button6.frame = CGRectMake(700, 400, 226, 275); 
    } 
} 
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation || UIInterfaceOrientationPortraitUpsideDown); 
} 
+0

안녕하세요 sagar, 고마워요. 나는 노력했고 일종의 일을했습니다. 나는 또 다른 문제가 있습니다. 가로로 내비게이션 콘트롤러를 돌리면 화면에서 약간 아래로 나타납니다. 올바르게 설정하는 방법? – Cathy

0

, 뷰 개체를 선택하고 속성 윈도우의 "보기 속성"창에서 사용자가 상태 표시 줄 및 "탐색 모음"의 "최고 바"를 선택했는지 확인합니다 (앱이 가정 탐색 바). "시뮬레이트 된 사용자 인터페이스 요소"섹션의 맨 위에 표시됩니다. UIViewController의 뷰 크기를 결정할 때 앱에 항상 공간을 남겨 두도록 앱에 알립니다.