Cod*_*ter 20 iphone screen-orientation device-orientation ipad-3 ios6
我开发了iOS应用程序并在iOS6设备上进行了测试.在测试时,我意识到我的应用程序没有按预期响应方向更改.
这是我的代码:
// Autorotation (iOS >= 6.0)
- (BOOL) shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
确切地说,我想知道iOS中的方向更改调用了哪些方法.
She*_*pta 55
你可以尝试这个,可以帮助你:
要么
Objective-C的:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]
Run Code Online (Sandbox Code Playgroud)
迅速:
if UIDevice.current.orientation.isLandscape {
// Landscape mode
} else {
// Portrait mode
}
Run Code Online (Sandbox Code Playgroud)
Gir*_*ish 36
你可以尝试这个,这解决了你的问题.
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
Run Code Online (Sandbox Code Playgroud)
请参阅以下链接App extension
获取设备当前方向(应用程序扩展)
也许是愚蠢但它有效(仅在ViewController中):
if (self.view.frame.size.width > self.view.frame.size.height) {
NSLog(@"Hello Landscape");
}
Run Code Online (Sandbox Code Playgroud)
@property (nonatomic) UIDeviceOrientation m_CurrentOrientation ;
Run Code Online (Sandbox Code Playgroud)
/*您需要在ViewDidload或ViewWillAppear*/中声明这些代码
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
}
Run Code Online (Sandbox Code Playgroud)
/*现在我们的设备会在我们更改设备方向时发出通知,因此您可以使用当前方向控制代码或程序*/
- (void)deviceOrientationDidChange:(NSNotification *)notification
{
//Obtaining the current device orientation
/* Where self.m_CurrentOrientation is member variable in my class of type UIDeviceOrientation */
self.m_CurrentOrientation = [[UIDevice currentDevice] orientation];
// Do your Code using the current Orienation
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
55909 次 |
最近记录: |