2009-08-25 5 views
4

내 앱이 시작될 때 시작 화면을로드 중입니다. 그런 다음 TabBarController 및 ViewControllers를로드하려고합니다. 그러나 내 TabBarController 창이 화면 크기에 맞게 조정되지 않습니다.보기의 하위보기로 TabBarController 추가

아마도 하단의 TabBar 중 3/4이 잘 리기 시작하고 상태 표시 줄 아래의 화면 상단에 슬림 한 aprox 20 픽셀 갭이 있습니다. TabBarController의 크기를 올바르게 조정하려면 어떻게해야합니까? 나는 마지막으로 작동가 someting을 발견

-(void)loadView{ 
// Init the view 
CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; 
UIView *view = [[UIView alloc] initWithFrame:appFrame]; 
view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 
self.view = view; 
[view release]; 

splashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Splash.png"]]; 
splashImageView.frame = CGRectMake(0,0,320,458); 
[self.view addSubview:splashImageView]; 

viewController = [[FlashCardViewController alloc] initWithNibName:@"FlashCardViewController" bundle:[NSBundle mainBundle]]; 
//viewController.view.bounds = [[UIScreen mainScreen]bounds]; 
viewController.title = @"Quiz"; 
viewController.tabBarItem.image = [UIImage imageNamed:@"puzzle.png"]; 

UIViewController *viewController2 = [[UIViewController alloc] initWithNibName:nil bundle:nil]; 
viewController2.title = @"Nada"; 
viewController2.tabBarItem.image = [UIImage imageNamed:@"magnifying-glass.png"]; 
//viewController.view.alpha = 0.0; 
//[self.view addSubview:viewController.view]; 

tabBarController = [[UITabBarController alloc] init]; 
tabBarController.viewControllers = [NSArray arrayWithObjects:viewController, viewController2, nil]; 
[viewController2 release]; 
tabBarController.view.alpha = 0.0; 
//tabBarController.tabBarItem.image = [UIImage imageNamed:@"State_California.png"]; 
//tabBarController.tabBarItem.title = @"State_California.png"; 
tabBarController.view.bounds = [[self view] bounds]; 
//tabBarController.view.frame = [[UIScreen mainScreen] applicationFrame]; 
[self.view addSubview:tabBarController.view]; 

timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fadeScreen) userInfo:nil repeats:NO]; 
} 
-(void) fadeScreen 
{ 
[UIView beginAnimations:nil context:nil]; // begin animation block 
[UIView setAnimationDuration:0.75]; // sets animation duration 
[UIView setAnimationDelegate:self]; // sets the delegate for this block 
[UIView setAnimationDidStopSelector:@selector(finishedFading)]; // Calls finishFading 
self.view.alpha = 0.0; // // Fades the alpha to 0 over animation 
[UIView commitAnimations]; // Commits this block, done 
} 

-(void) finishedFading 
{ 
[UIView beginAnimations:nil context:nil]; // Begin animation block 
[UIView setAnimationDuration:0.75]; // set duration 
self.view.alpha = 1.0; // fades the view to 1.0 alpha over .75 seconds 
//viewController.view.alpha = 1.0; 
tabBarController.view.alpha = 1.0; 
[UIView commitAnimations]; 
[splashImageView removeFromSuperview]; 
} 

답변

5

: 여기

는 시작보기를로드 내 SplashViewController의 코드 및 TabBarController입니다. 대신에 :

tabBarController.view.frame = [[UIScreen mainScreen] applicationFrame]; 

또는

tabBarController.view.bounds = [[self view] bounds]; 

내가 찾아이 크기 자동 또는 명명 된 설정을 할 수 없기 때문에

, 나는 화면을 뺀 상태 표시 줄의 크기입니다 내 자신의 사각형을 만들어야했습니다 .

tabBarController.view.frame = CGRectMake(0,0,320,460); 
+0

viewWillAppear에서 self.tabBarController.view.frame = [[self view] frame]을 실행하면 해당 지점에서 경계 및 프레임이 올바르게 계산 되었기 때문에 숫자를 직접 계산하지 않아도 작동합니다. – pulkitsinghal

+0

이 더 나은 답변 : tabBarController.view.frame = CGRectMake (0, 0, self.view.frame.size.width, self.view.frame.size.height); 너비와 높이가 사용자가 사용하는 각 장치에 따라 다르기 때문에? – lakesh

12

나는 거의 똑같은 일을 끝내고 같은 문제에 부딪쳤다.

@interface Test1ViewController : UIViewController { 
    IBOutlet UITabBarController *tbc; 
} 

@property (nonatomic,retain) IBOutlet UITabBarController *tbc; 
@end 
  • 뷰 XIB가 XIB

  • TabBarViewController 추가 Test1View

  • 라는 만듭니다

    1. 은 엑스 코드에서 뷰 컨트롤러 클래스는 다음 Test1ViewController에게 전화를 추가 만들기

      XIB의 파일 소유자를으로 설정하십시오..

    2. 파일 소유자의 IBOutlet을 XIB의 Tab Bar Controller에 연결하십시오.

    3. 파일 소유자의 IBOutlet을 XIB의보기에 연결하십시오. 당신의 SplashViewController.h에서

    4. SplashViewController.m에서 tabBarViewController을 합성하여 재산

      Test1ViewController *tabBarViewController; 
      
    5. 를 추가합니다.

    6. 은 다음과 SplashViewControllerloadView 방법에 TabBarController 생성 코드를 바꿉니다 :

      tabBarViewController = [[Test1ViewController alloc] initWithNibName: 
           @"Test1View" bundle:[NSBundle mainBundle]]; 
      tabBarViewController.view.alpha = 0.0; 
      [self.view addSubview:[tabBarViewController view]]; 
      
    7. 여기에 나를 위해 실종 된 비트입니다.Test1ViewController.m에서는 viewDidLoad 방법에 다음 줄을 추가해야합니다

      self.view = tbc.view; 
      
    8. 마지막으로, 나는 또한 tabBarViewController보기에 1.0 알파를 설정 SplashViewController.mfinishedFading 방법을 변경했다.

      -(void) finishedFading 
      { 
          [UIView beginAnimations:nil context:nil]; 
          [UIView setAnimationDuration:0.75]; 
          self.view.alpha = 1.0; 
          tabBarViewController.view.alpha = 1.0; 
          [UIView commitAnimations]; 
          [splashImageView removeFromSuperview]; 
      } 
      

    나는이 도움이되기를 바랍니다.

  • +0

    고마워, 나는 비슷한 것을 찾고 있었다. 물건을 평가 해. –

    +0

    감사합니다. 나는 내 인생을 위해 그것을 작동시키지 못했다. 내가 10 단계를 놓쳤다는 것을 알게되었다. – link664

    +0

    이 대답의 거의 모든 것이 10 단계가 아니라 다른 것이었다. 지금은 작동하지 않는 어떤 이유로, 아마 iOS5 맡은 일? 대신 viewWillAppear에서 self.tabBarController.view.frame = [[self view] frame]을 삽입하면 나에게 트릭이 생겼다. – pulkitsinghal

    관련 문제