كيفية جعل التطبيق يعمل بشكل صحيح للتشغيل التلقائي في نظام التشغيل iOS 6؟

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

سؤال

في نظام التشغيل iOS6، shouldAutorotateToInterfaceOrientation تم إهماله.حاولت استخدامها supportedInterfaceOrientations و shouldAutorotate لجعل التطبيق يعمل بشكل صحيح للتدوير التلقائي ولكنه فشل.

لا أريد تدوير وحدة التحكم ViewController هذه، ولكنها لا تعمل.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

أيه أفكار؟شكرا على أي مساعدة مقدما!

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

المحلول

اكتشفه.

1) فئة فرعية UINavigationController (سوف يتحكم في Top ViewController للتسلسل الهرمي في الاتجاه.) قام بتعيينه على أنه self.window.rootviewController.

- (BOOL)shouldAutorotate
{
    return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return self.topViewController.supportedInterfaceOrientations;
}

2) إذا كنت لا تريد عرض تدوير وحدة التحكم

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

3) إذا كنت تريد أن تكون قادرة على التدوير

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

راجع للشغل، وفقا لاحتياجاتك، طريقة أخرى ذات صلة:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return UIInterfaceOrientationMaskPortrait;
}

نصائح أخرى

إذا كنت تستخدم وحدة تحكم شريط علامات التبويب بدلاً من وحدة تحكم التنقل كوحدة تحكم جذر، فستحتاج إلى فئة فرعية مماثلة UITabBarController.

كما سيكون بناء الجملة مختلفا.لقد استخدمت ما يلي بنجاح.استخدمت بعد ذلك الأمثلة المذكورة أعلاه بنجاح على وحدات التحكم في العرض التي أردت تجاوزها.في حالتي، كنت أرغب في عدم تدوير الشاشة الرئيسية ولكن كان لدي شاشة الأسئلة الشائعة التي تحتوي على أفلام وأردت بطبيعة الحال تمكين العرض الأفقي.عملت على أكمل وجه!ما عليك سوى ملاحظة تغيير بناء الجملة إلى self.modalViewController (ستحصل على تحذير مترجم إذا حاولت استخدام بناء الجملة لوحدة تحكم التنقل.) آمل أن يساعدك هذا!

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)shouldAutorotate
{
    return self.modalViewController.shouldAutorotate;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return self.modalViewController.supportedInterfaceOrientations;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top