UIDeviceOrientationDidChangeNotification 多次调用,加速度计发生微小变化

发布于 2024-11-26 20:31:40 字数 353 浏览 5 评论 0原文

我用来

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

更改我的应用程序委托中的某些视图。

但这是在加速度计的微小变化中被调用的。任何人都可以建议任何解决方法,以便仅在设备完全旋转时才调用它。 谢谢

I am using

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

to make changes to some views in my appdelegate.

But this gets called in a slightest variation of the accelerometer. Can anyone suggest any workaround, so that it gets only called when the device is completely rotated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Bonjour°[大白 2024-12-03 20:31:40

您能否在发布通知之前编写一些代码来检查设备的宽度 = 480 和高度 = 320(这是设备旋转 90 度时的情况)?

所以像这样:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

...

if(width == 480 && height == 320)
{
    [[NSNotificationCenter defaultCenter] postNotification . . . ];
}

Could you write some code to check the device's width = 480 and height = 320 (this is when the device has been rotated 90 degrees) before posting the notification?

So something like:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

...

if(width == 480 && height == 320)
{
    [[NSNotificationCenter defaultCenter] postNotification . . . ];
}
情泪▽动烟 2024-12-03 20:31:40
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     //your code here
}

在视图控制器中重写此方法。当设备旋转到新方向时它将被调用

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     //your code here
}

override this method in your view controller. It will get called when the device has rotated to a new orientation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文