设备方向没有得到。
目前我在IOS 7上工作,我的问题是我无法取得当前设备在ViewDidLoad方法的方向。
- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return (UIInterfaceOrientationMaskAll); } - (void)viewDidLoad { [super viewDidLoad]; if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){ NSLog(@"i am in landscape mode"); } if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){ NSLog(@"i am in portrait mode"); } }
我在我的FirstViewController.m
编写这段代码,当我运行我的应用程序没有条件成为他们真的,任何人都可以帮助我为什么没有条件成为真正的,即使我在纵向模式下运行我的应用程序。 提前致谢。
尝试这个。
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if(UIInterfaceOrientationIsLandscape(orientation)) { //Landscape mode } else { //Portrait mode }
编辑 :使用UIInterfaceOrientationIsLandscape
和UIInterfaceOrientationIsPortrait
方法来查找orientation mode
尝试这个
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (UIDeviceOrientationIsLandscape(orientation)) { NSLog(@"i am in landscape mode"); } if (UIDeviceOrientationIsPortrait(orientation)){ NSLog(@"i am in portrait mode"); }
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
和这一个刚刚在第二个之后- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
, 例如
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { UIInterfaceOrientation orientation = toInterfaceOrientation; //hear toInterfaceOrientation contains the which orientation is device is turning to if (UIDeviceOrientationIsLandscape(orientation)) { NSLog(@"i am in landscape mode"); } if (UIDeviceOrientationIsPortrait(orientation)){ NSLog(@"i am in portrait mode"); } } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { UIInterfaceOrientation orientation = fromInterfaceOrientation; // hear fromInterfaceOrientation contains previous state of the orientation if (UIDeviceOrientationIsLandscape(orientation)) { NSLog(@"i am in landscape mode"); } if (UIDeviceOrientationIsPortrait(orientation)){ NSLog(@"i am in portrait mode"); } }
欲了解更多信息,请参阅文档
希望这有助于你.. 🙂