gpt4 book ai didi

iphone - 无法检测 iPhone 上的纵向方向

转载 作者:行者123 更新时间:2023-12-03 21:19:14 24 4
gpt4 key购买 nike

当我旋转横向时,我显示一个模态视图 Controller 。我想在纵向时删除模态视图 Controller 。由于某种原因,当我进入纵向模式时,我的日志语句不会出现。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {

NSLog(@"showing chart");
[self presentModalViewController:landscapeChartViewController animated:NO];
}

if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"dismissing chart");
[self.parentViewController dismissModalViewControllerAnimated:NO];
}
}

最佳答案

您可以稍微简化此代码,可能有助于缩小范围。

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES; // Return YES is the same as entering all interfaces.
}


-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {

NSLog(@"showing chart");
[self presentModalViewController:landscapeChartViewController animated:NO];
}

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
NSLog(@"dismissing chart");
[self.parentViewController dismissModalViewControllerAnimated:NO];
// self.parentViewController seems like a call FROM the modalViewController.
// This should be moved to the modalViewControllers implementation
}
}

仅从外观上看,我认为您需要关闭模态视图内的模态视图 Controller ,而不是父 View 内的模态视图 Controller 。因此,您可以在主 Controller 中使用横向版本,然后将“willAnimateRotation...”添加到模态 Controller 来处理纵向旋转状态。

关于iphone - 无法检测 iPhone 上的纵向方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6554886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com