التوجه تغير الحاجة ولكن فقط من أجل واحدة من عدة وجهات النظر في TabBarViewController

StackOverflow https://stackoverflow.com/questions/1341874

سؤال

وبلدي التطبيقات لديه UITabBarController مع خمسة علامات التبويب. كنت بحاجة لتوجهات تناوب فقط لعلامة التبويب الخامس. وكنت قادرا على الحصول على كل خمسة لتدوير إلى المشهد من قبل إن شاء subclasses ترث وUITabBarController

@implementation TabBarControllerRotate

-(BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation {

//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight 
          || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
          || interfaceOrientation == UIInterfaceOrientationPortrait);
}

end

if(tbc == nil){
    //tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil];        
    tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil];  ////// new  //////

....

tbc.viewControllers = 
[NSArray arrayWithObjects:viewController1, viewController2, viewController3
 ,viewController4,viewController5, nil];

وأحتاج الآن لإيقاف دوران viewController1 - 4. حاولت دون جدوى القيام بذلك عن طريق إضافة التعليمة البرمجية التالية إلى أربعة ملفات. م * ل هذه viewControllers.

- (BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation {

return NO;
}

يرجى تقديم المشورة لي حول كيفية الحصول R تم. شكرا للقراءة، مارك

هل كانت مفيدة؟

المحلول

وأفترض أن هناك أسهل طرق أخرى للقيام بذلك، لكنني في النهاية حصلت على الحل. عنوان viewController الخامس في TabBarController، واحد فقط هذا يحتاج إلى تغيير التوجه، هو "MyNotes"

ومن داخل SubListViewController.m يتم إنشاء الكائن TabBarControllerRotate.

  tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil];
  tbc.viewControllers = [NSArray arrayWithObjects:viewController1
          , viewController2, viewController3, viewController4, viewController5, nil
  tbc.delegate = self;

وTabBarController فرعية UITabBarController ويتضمن خاصية BOOL اسم bMyNotes.

وSubListViewController هو UITabBarControllerDelegate

وفي كل مرة يتم تغيير طريقة العرض في TabBarController يتم إرسال الرسالة، وهي   - (باطل) tabBarController: (UITabBarController *) tabBarController       didSelectViewController: (UIViewController *) viewController

وذلك SubListViewController.m يحتوي هذا الرمز:

   #pragma mark UITabBarControllerDelegate methods

   - (void)tabBarController:(UITabBarController *)tabBarController 
        didSelectViewController:(UIViewController *)viewController{
    BOOL b = (viewController.title == @"MyNotes");
    [tbc setBMyNotesTab:b];
    //NSLog(@"MyNotesTab == %d", [tbc bMyNotesTab]);

   }

وبعد ذلك TabBarControllerRotate.m يحتوي على:

    - (BOOL)shouldAutorotateToInterfaceOrientation:
          (UIInterfaceOrientation)interfaceOrientation {

        //NSLog(@"bMyNotesTab is: %d",self.bMyNotesTab);

        return ( (interfaceOrientation == UIInterfaceOrientationLandscapeRight 
            || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
            || interfaceOrientation == UIInterfaceOrientationPortrait
                 ) && self.bMyNotesTab 
               );
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top