gpt4 book ai didi

ios - 接收方向更改通知时 StatusBar 方向错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:29:11 26 4
gpt4 key购买 nike

我注册了 2 个 View Controller 以接收设备方向更改通知。 `

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repositionView) name:UIDeviceOrientationDidChangeNotification object:nil];

`

在我的重新定位 View 方法中:

   UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

if (UIInterfaceOrientationIsLandscape(orientation)) {
NSLog(@"view (%@) will set orientation landscape",self);
// do smt
} else {
NSLog(@"view (%@) will set orientation portrait",self);
//do smt else
}

方向改变时它们都在内存中

2013-11-27 17:37:54.277 App[13782:70b] view (<ViewController: 0xbf09950>) will set orientation landscape
2013-11-27 17:37:54.286 App[13782:70b] view (<ViewController: 0xc095e40>) will set orientation portrait
2013-11-27 17:38:17.318 App[13782:70b] view (<ViewController: 0xbf09950>) will set orientation portrait
2013-11-27 17:38:20.123 App[13782:70b] view (<ViewController: 0xc095e40>) will set orientation landscape

只有一个接收到正确的方向。为什么是这样 ?我该如何解决?

最佳答案

使用 UIApplicationDidChangeStatusBarOrientationNotification 而不是 UIDeviceOrientationDidChangeNotification。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repositionView:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];


-(void)repositionView:(NSNotification *)notification
{
UIInterfaceOrientation orientation = [[[notification userInfo] objectForKey: UIApplicationStatusBarOrientationUserInfoKey] integerValue];

if (UIInterfaceOrientationIsLandscape(orientation)) {
NSLog(@"view (%@) will set orientation landscape",self);
// do smt
} else {
NSLog(@"view (%@) will set orientation portrait",self);
//do smt else
}

}

关于ios - 接收方向更改通知时 StatusBar 方向错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20246911/

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