Как установить ориентацию приложения iPhone в UIDeviceOrientationIsPortrait?

#ios #iphone #orientation

#iOS #iPhone #ориентация

Вопрос:

Я разрабатываю приложение для IOS, я использую следующий код для блокировки orientation приложения.

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

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
  

Если orientation это UIInterfaceOrientationPortrait Когда запустите приложение. Это заблокирует orientation to UIInterfaceOrientationPortrait .

Но view Landscape при запуске приложения все еще отображается Landscape .

Как установить Orientation UIDeviceOrientationIsPortrait для приложения значение для запуска приложения, независимо от того, является ли телефон Landscape «портретным» или «портретным»?

Ответ №1:

Если вам нужно заблокировать все приложение в портретном режиме, перейдите в раздел ЦЕЛИ -> Вкладка Общие -> Информация о развертываниивведите описание изображения здесь

Это заблокирует все приложение в портретном режиме

Ответ №2:

Если вам нужна только одна ориентация для всего приложения, перейдите к разделам цели, Общие сведения и информация о развертывании. Затем проверьте портрет.

Ответ №3:

Я использую следующий код для настройки Orientation Portrait .

 - (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated] ;



    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

    //set the orientation is Portrait when the App start.
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        objc_msgSend([UIDevice currentDevice], @selector(setOrientation:),    UIInterfaceOrientationPortrait );
    }
}