我可以观察UIViewController更改interfaceOrientation吗?
如果我有一个指向UIViewController的指针,当它改变interfaceOrientation而不修改控制器的代码时,我可以得到通知吗?
我最好的办法是检测设备方向的变化,然后看看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"); }
你可以在你的UIViewController上使用willAnimateRotationToInterfaceOrientation:duration:
方法,然后重新定位横向或纵向的任何UIViews(或任何其他代码)。 例如
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { // change positions etc of any UIViews for Landscape } else { // change position etc for Portait } // forward the rotation to any child view controllers if required [self.rootViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; }
- 'GPUImageOutput <GPUImageInput>'没有可见的@interface声明select器'imageFromCurrentlyProcessedOutputWithOrientation:'
- Swift – 线程1:信号SIGABRT
- 密码validation的正则expression式Objective-C
- 如何取消NSOperationQueue
- 如何将NSURLConnection与UIProgressView集成?
- iOS – 防止iPhoneconfiguration文件被删除或检查是否已安装
- 在button上单击iOS中的另一个视图控制器
- 如何将使用AVFoundation拍摄的照片保存到相册?
- 在iOS应用程序中运行Python脚本