iphone - 如何在 iOS 中实现这一点?

标签 iphone ios objective-c cocoa-touch panoramas

我指的是 DMD Panorama 应用程序。

如您所见,此图片的顶部有一个阴阳符号。

enter image description here

一旦我们旋转设备,两个符号就会靠近,如下所示:

enter image description here

能否请您告诉我如何检测设备的旋转,以便当设备旋转时,这两张图像靠得更近?

感谢您的回复。

最佳答案

在 viewWillAppear 函数中添加通知器

-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];}

方向改变通知这个函数

- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}

在处理 moviePlayerController 帧的方向时依次调用此函数

- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {

if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
    //load the portrait view    
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
{
    //load the landscape view 
}}

在 viewDidDisappear 移除通知

-(void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];}

关于iphone - 如何在 iOS 中实现这一点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19109165/

相关文章:

ios - 在 iOS 中获取谷歌地图的中心

iphone - UINavigationController 和 UIViewController 释放

ios - Designables : Failed to render and update auto layout status. 我正在使用 Xcode 9.3

iphone - 如何根据 CGSize 更改缩放 CGPoint?

objective-c - 如何在 Swift 3x 中的条形图上实现轨迹球和访问标签

ios - 如何获取 UIStoryBoard segued UITabbarController 引用

ios - 创建子 UIView 的 UIView 正在生成层次结构约束警告

html - 内部导航被拒绝 : <allow-navigation not set> in Cordova on iOS

ios - 如何在其他 View 生成之前完成一个 View 约束

ios - ARC 并在编译时不指定类就向对象发送消息