Swift ViewController即使强制也不会进入纵向模式

Swift ViewController即使强制也不会进入纵向模式,swift,objective-c,uiviewcontroller,Swift,Objective C,Uiviewcontroller,我有一个UIViewController,我以横向模式显示它。在某个时刻,此屏幕将打开Spotify应用程序进行授权,并自动打开我们的应用程序 在此之后,应用程序需要在纵向模式下转到下一个视图控制器: let storyboard = UIStoryboard(name: "NewPage", bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: "New

我有一个
UIViewController
,我以
横向
模式显示它。在某个时刻,此屏幕将打开
Spotify
应用程序进行授权,并自动打开我们的应用程序

在此之后,应用程序需要在
纵向模式下转到下一个视图控制器:

    let storyboard = UIStoryboard(name: "NewPage", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "NewPage")
    navigationController?.pushViewController(vc, animated: true)
无论我在下一页做什么,它都保持横向模式。这里是我试图在肖像模式下展示的内容

-(void)viewWillAppear
{
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}

-(void) setOrientationToPortrait
{
    if ([[UIDevice currentDevice]orientation] != UIInterfaceOrientationPortrait)
    {
        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }
}

-(BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
    [self updateLayoutsForCurrentOrientation:toInterfaceOrientation view:self.navigationController.view.superview.superview];
}
不幸的是,
应该自动旋转
将动画化接口定向
甚至都不调用


注意:如果我在iPhone中按home(主页)按钮并返回应用程序,则纵向模式会工作。

在按下之前是否可以旋转?另外,我一直不喜欢使用
[[UIDevice currentDevice]setValue:value-forKey:@“orientation”]的未记录方法
,对我来说,它闻起来像是在使用私有API。我试着使用导航控制器,它成功了。谢谢@matt