How do I detect a rotation on the iPhone without the device autorotating?(如何在没有设备自动旋转的情况下检测 iPhone 上的旋转?)
问题描述
有人知道怎么做吗?
我是这么想的:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
}
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}
- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
}
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
}
可能会阻止设备旋转(覆盖我的 UIViewController 的所有旋转方法而不调用超类),但我担心实际执行旋转的不是 UIViewController.
may prevent the device from rotation (overriding all rotate methods of my UIViewController and not calling the superclass) but I fear it's not the UIViewController that actually performs the rotation.
我的 UIViewController 在 UINavigationController 中.
My UIViewController is in a UINavigationController.
有人有什么想法吗?
干杯,尼克.
推荐答案
你可以注册通知UIDeviceOrientationDidChangeNotification(来自UIDevice.h),然后当你关心关于方向变化调用这个方法:
You can register for the notification UIDeviceOrientationDidChangeNotification (from UIDevice.h), and then when you care about orientation changes call this method:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
当你不再关心方向变化时,调用这个方法:
When you no longer care about orientation changes, call this method:
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
通知将在适用时发送,您可以检查 [UIDevice currentDevice].orientation 了解当前方向是什么.
The notification will be sent when applicable, and you can check [UIDevice currentDevice].orientation to find out what the current orientation is.
这篇关于如何在没有设备自动旋转的情况下检测 iPhone 上的旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在没有设备自动旋转的情况下检测 iPhone 上的旋转?
基础教程推荐
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
