gpt4 book ai didi

iphone - 我怎么知道 AppDelegate 中的方向发生了变化

转载 作者:可可西里 更新时间:2023-11-01 17:09:14 25 4
gpt4 key购买 nike

设备如何知道方向改变的功能是 -(void)viewWillLayoutSubviews 和-(void)viewDidLayoutSubviews但是,它们只是在 Controller 中;现在我想知道在 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]);
}

或者查看 UIApplicationDidChangeStatusBarOrientationNotification 的文档这将为您提供

关于iphone - 我怎么知道 AppDelegate 中的方向发生了变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14836828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com