gpt4 book ai didi

ios - 我可以观察 UIViewController 何时更改 interfaceOrientation 吗?

转载 作者:技术小花猫 更新时间:2023-10-29 10:08:57 24 4
gpt4 key购买 nike

如果我有一个指向 UIViewController 的指针,当它改变 interfaceOrientation 时我是否可以在不修改 Controller 代码的情况下得到通知?

我最好的选择是检测设备方向的变化,然后查看 UIViewController 是否会/有旋转(d)?

最佳答案

你可以使用 NSNotificationCenter :

 [[NSNotificationCenter defaultCenter] addObserver:self // put here the view controller which has to be notified
selector:@selector(orientationChanged:)
name:@"UIDeviceOrientationDidChangeNotification"
object:nil];
- (void)orientationChanged:(NSNotification *)notification{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

//do stuff
NSLog(@"Orientation changed");
}

关于ios - 我可以观察 UIViewController 何时更改 interfaceOrientation 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14387735/

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