gpt4 book ai didi

ios - 如何在 ios 中执行连续方向检测?

转载 作者:行者123 更新时间:2023-11-29 10:56:48 24 4
gpt4 key购买 nike

我有一个简单的 if 语句来检测方向并执行操作。这很好用,但它只在第一次有效并且无法再次检测到。

这个 void 是否只被调用一次,如果是,我如何改变它以不断检查?

我需要将一些移动到 viewDidLoad 吗?

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)

{
[self.navigationController pushViewController:graphView animated:YES];

}

else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
[self.navigationController pushViewController:graphView animated:YES];
}

else if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
[self.navigationController popToRootViewControllerAnimated:YES];
NSLog(@"portrait");
}

else
{
[self.navigationController popToRootViewControllerAnimated:YES];

}

}

最佳答案

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

关于ios - 如何在 ios 中执行连续方向检测?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17913010/

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