Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何知道AppDelegate中的方向已更改_Iphone_Ios_Objective C_Screen Orientation - Fatal编程技术网

Iphone 如何知道AppDelegate中的方向已更改

Iphone 如何知道AppDelegate中的方向已更改,iphone,ios,objective-c,screen-orientation,Iphone,Ios,Objective C,Screen Orientation,设备如何知道方向变化的功能是 -(无效)视图将布局子视图和 -(无效)ViewDidLayoutSubView 但是,它们只是在控制器中; 现在我想知道有没有类似的函数可以知道AppDelegate.m文件中方向的变化 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController

设备如何知道方向变化的功能是 -(无效)视图将布局子视图和 -(无效)ViewDidLayoutSubView 但是,它们只是在控制器中; 现在我想知道有没有类似的函数可以知道AppDelegate.m文件中方向的变化

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated {

    UINavigationBar *morenavbar = navigationController.navigationBar;
    UINavigationItem *morenavitem = morenavbar.topItem;
    //We don't need Edit button in More screen.
    morenavitem.rightBarButtonItem = nil;
    morenavitem.title = nil;
    UIImage *backgroundImage = [UIImage imageNamed:@"nav.png"];

    [morenavbar setBackgroundImage:backgroundImage 
         forBarMetrics:UIBarMetricsDefault];

    UIDeviceOrientation currentDeviceOrientation = 
           [[UIDevice currentDevice] orientation];
    UIInterfaceOrientation currentInterfaceOrientation = 
           [[UIApplication sharedApplication] statusBarOrientation];
    if (UIDeviceOrientationIsLandscape(currentDeviceOrientation)||
        UIDeviceOrientationIsLandscape(currentInterfaceOrientation)){
        UIImage *backgroundImageLandscape = [UIImage imageNamed:@"navbar_landscape.png"];
        [morenavbar setBackgroundImage:backgroundImageLandscape forBarMetrics:UIBarMetricsDefault];
    }

}

您可以在发生旋转时注册通知

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleDidChangeStatusBarOrientationNotification:) 
                                             name:UIApplicationDidChangeStatusBarOrientationNotification 
                                           object:nil];
然后实现在发送消息时调用的方法

- (void)handleDidChangeStatusBarOrientationNotification:(NSNotification *)notification;
{
  // Do something interesting
  NSLog(@"The orientation is %@", [notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey]);
}

或者,也可以查看为您提供界面方向信息的文档。如果您正在谈论界面方向,您可以查看
UIApplicationIDChangeStatusBarOrientationNotification
,如果您希望在设备方向更改时收到通知,您可以查看
UIDeviceOrientationIDChangeNotification