小编ZHE*_*ENG的帖子

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

设备如何知道方向变化的功能是 - (void)viewWillLayoutSubviews和 - (void)viewDidLayoutSubviews但是,它们只是在控制器中; 现在我想知道是否有这样的函数来了解文件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];
    }

}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c screen-orientation ios

3
推荐指数
1
解决办法
3608
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1

screen-orientation ×1