تغيير عرض على علامة تبويب واحدة فقط في تطبيق Tabbar (صورة المناظر الطبيعية)؟

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

سؤال

كيف يمكنني تغيير طريقة العرض عند تدوير iPhone (تغيير NIB). ولكن يجب أن يحدث فقط في علامة تبويب واحدة! حاولت ذلك مع:

    - (void)viewDidLoad {
 LandscapeViewController *viewController = [[LandscapeViewController alloc]
             initWithNibName:@"LandscapeView" bundle:nil];
 self.landscapeViewController = viewController;
 [viewController release];

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
             name:UIDeviceOrientationDidChangeNotification object:nil]; }

- (void)orientationChanged:(NSNotification *)notification
{
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
 {
        [self presentModalViewController:self.landscapeViewController animated:YES];
        isShowingLandscapeView = YES;
    }
 else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
 {
        [self dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }    
}

ولكن بعد ذلك، تظهر عرض المناظر الطبيعية في جميع علامات التبويب. (عند تحميل هذا الرمز مرة واحدة). اي فكرة؟

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

المحلول 3

خزانات لتعليقاتك! لقد وجدت الحل البديل:

//Remove Observer if not in Landscape
- (void)viewDidDisappear:(BOOL)animated {
    if (isShowingLandscapeView == NO) {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
    }   
}

//Add Observer if not in Landscape
- (void)viewDidAppear:(BOOL)animated {
    if (isShowingLandscapeView == NO) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
    }
}

نصائح أخرى

ما يحدث هو وحدة التحكم في الرأي الخاص بك يتلقى UIDeviceOrientationDidChangeNotification إشعار كلما تغير الدوران، ما إذا كان يتم عرضه أم لا. بدلا من ذلك، حاول استخدام طرق المدمجة UIViewController وهذا يعني للاستجابة للتناوب.

http://tinyurl.com/ycb8of2.

هذا من مستندات Apple (عرض دليل برمجة تحكم):

تحكم شريط علامة التبويب وعرض دوران

تدعم وحدات تحكم شريط التبويب اتجاه صورة افتراضيا ولا تتناوب إلى اتجاه أفقي ما لم يدعم جميع وحدات تحكم الرؤية الجذر هذه الاتجاه. عند حدوث تغيير اتجاه الجهاز، تستعلم وحدة تحكم شريط التبويب صفيفها من وحدات تحكم العرض. إذا لم يدعم أي واحد منهم التوجيه، فإن وحدة تحكم شريط التبويب لا يغير اتجاهه.

لذلك، لست متأكدا من أن وحدة تحكم شريط التبويب مصممة لتدوير عرض واحد فقط.

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