更改方向时屏幕旋转了很多次

问题描述 投票:0回答:1

我有2个屏幕:第一个屏幕支持所有方向,第二个屏幕仅支持横向右方向。我希望第一个屏幕在保存到第二个屏幕之前先保存其方向,并在从第二个屏幕弹出时返回该方向。

我的代码:

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIDevice currentDevice] setValue:@(currentOrientaion) forKey:@"orientation"];
    [UIViewController attemptRotationToDeviceOrientation];
}

正在工作,但有时屏幕旋转许多次以改变方向。有人帮助我:为什么?

ios objective-c swift orientation
1个回答
0
投票

您应使用“ ViewDidLoad”之类的其他方法来调用这些行,因为对于特定的视图控制器,“ viewWillAppear”方法可能会调用多次。

© www.soinside.com 2019 - 2024. All rights reserved.