سؤال

أنا أحمل شاشة البداية عندما يبدأ تطبيقي. ثم أريد تحميل tabbarcontroller و viewcontrollers. ومع ذلك، فإن نافذة tabbarcontroller الخاصة بي لا الحجم إلى حجم الشاشة.

ربما يتم قطع 3/4 من Tabbar في الجزء السفلي، وهناك فجوة SILL APOX 20 بكسل في الجزء العلوي من الشاشة أسفل شريط الحالة. كيف يمكنني تغيير حجم tabbarcontroller بشكل صحيح؟

هنا هو رمز في SplashViewController تحميل طريقة عرض البداية، و tabbarcontroller:

 -(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];
}
هل كانت مفيدة؟

المحلول 2

وجدت أخيرا سوميتينغ التي تعمل. بدلا من:

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

أو

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

نظرا لأنني لم أستطع العثور على إعدادات أو تلقائية أو مسماة لهذا الحجم، كان علي إنشاء مستطيلي الخاص هو حجم الشاشة ناقص شريط الحالة.

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

نصائح أخرى

لقد أكملت للتو نفس الشيء وركضت في نفس المشكلات ولكن في النهاية حصلت عليها تعمل.

  1. إنشاء فئة تحكم عرض في Xcode يسمى Test1ViewController وإضافة ما يلي:

    @interface Test1ViewController : UIViewController {
        IBOutlet UITabBarController *tbc;
    }
    
    @property (nonatomic,retain) IBOutlet UITabBarController *tbc;
    @end
    
  2. إنشاء عرض XIB يسمى Test1View

  3. أضف TabBarViewController إلى XIB.

  4. اضبط صاحب الملف في XIB ليكون Test1ViewController.

  5. ربط tbc iBoutlet في مالك الملف إلى وحدة تحكم شريط التبويب في XIB.

  6. ربط view iboutlet في مالك الملف إلى العرض في XIB.

  7. في SplashViewController.h أضف العقار

    Test1ViewController *tabBarViewController;
    
  8. توليف tabBarViewController في الخاص بك SplashViewController.m.

  9. استبدال الخاص بك TabBarController رمز إنشاء في الخاص بك loadView طريقة في SplashViewController كالآتي:

    tabBarViewController = [[Test1ViewController alloc] initWithNibName:
            @"Test1View" bundle:[NSBundle mainBundle]];
    tabBarViewController.view.alpha = 0.0;
    [self.view addSubview:[tabBarViewController view]];
    
  10. ها هي الشيء الذي فقد بالنسبة لي. في Test1ViewController.m, تحتاج إلى إضافة السطر التالي إلى viewDidLoad طريقة:

    self.view = tbc.view;
    
  11. أخيرا، كان علي أيضا تغيير finishedFading طريقة في SplashViewController.m لتعيين ألفا إلى 1.0 على tabBarViewController رأي.

    -(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];
    }
    

آمل أن يساعد هذا.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top