Force landscape ios 7 - программирование
Подтвердить что ты не робот

Force landscape ios 7

Я попытался использовать следующие методы, чтобы создать ландшафт на одном из моих представлений:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}

- (BOOL)shouldAutorotate{
    return YES;
}

Не работали. Обратите внимание, что я тестирую симулятор и iPad.

Спасибо

4b9b3361

Ответ 1

Вот как я заставил одно из моих представлений быть Пейзаж с помощью NavigationViewController:

  • Внедрен этот ответ: fooobar.com/questions/110246/...

  • Импортированное сообщение в контроллере View: objc/message.h

  • Добавлена ​​эта строка кода в методе viewDidLoad:

objc_msgSend ([UIDevice currentDevice], @selector (setOrientation:), UIInterfaceOrientationLandscapeLeft);

Надеюсь, что это поможет кому-то.

Ответ 2

Принятый ответ, похоже, не работает на iOS 7.1.2. (Он работает на симуляторе, но не работает во время работы на устройстве.)

Это похоже на работу:

[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];

[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];

Ответ 3

int shouldShowInLandscape = 0;

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(forceToLandscape:)
                                                 name:@"yourNameNotification"
                                               object:nil];

}

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
              return UIInterfaceOrientationMaskLandscapeLeft;
    } else {
            if(shouldShowInLandscape)
            {
                return UIInterfaceOrientationMaskLandscape;
            }
            return UIInterfaceOrientationMaskPortrait;
    }
}

-(void) forceToLandscape:(NSNotification*) theNot
{
    shouldShowInLandscape = [[theNot object] intValue];

}

//из UIViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"yourNameNotification"
     object:[NSString stringWithFormat:@"1"]];
}

-(void) viewDidDisappear:(BOOL)animated
{

        [[NSNotificationCenter defaultCenter]
     postNotificationName:@"yourNameNotification"
     object:[NSString stringWithFormat:@"0"]]; 

}

//удаляем уведомление