Iphone 如何通过选项卡和视图来检测设备方向?

Iphone 如何通过选项卡和视图来检测设备方向?,iphone,uitableview,uiview,orientation,accelerometer,Iphone,Uitableview,Uiview,Orientation,Accelerometer,我的应用程序在纵向和横向之间来回切换。我已将所有内容(标签、UIImageView、uilabels)对齐,以便在两个方向上重新定位。但是,只有当设备实际旋转时,才会发生变化。旋转后,当我在选项卡之间循环时,它只是显示为自动调整大小,而不是用户旋转时的设置方式 当点击不同的标签时,如何检测设备的方向并显示视图以反映方向 好的,我将其设置为ViewWillDisplay。它没有检测到方向并在我设置的位置显示内容,这有什么原因吗 -(void)viewWillAppear:(UIInterfaceO

我的应用程序在纵向和横向之间来回切换。我已将所有内容(标签、UIImageView、uilabels)对齐,以便在两个方向上重新定位。但是,只有当设备实际旋转时,才会发生变化。旋转后,当我在选项卡之间循环时,它只是显示为自动调整大小,而不是用户旋转时的设置方式

当点击不同的标签时,如何检测设备的方向并显示视图以反映方向

好的,我将其设置为ViewWillDisplay。它没有检测到方向并在我设置的位置显示内容,这有什么原因吗

-(void)viewWillAppear:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration{

 UIInterfaceOrientation toOrientation = self.interfaceOrientation;
 [UIView beginAnimations:@"move buttons" context:nil];
 [UIView setAnimationDuration:0.5f];
 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
 if(toOrientation == UIInterfaceOrientationPortrait
    || toOrientation == UIInterfaceOrientationPortraitUpsideDown)
 {
  aboutContent.frame = CGRectMake(20, 100, 280, 107);
  myLogo.frame = CGRectMake(-5, 20, 330, 65);
  bulletOne.frame = CGRectMake(40, 220, 240, 45);
  bulletTwo.frame = CGRectMake(40, 270, 240, 45);
 }
 else
 {
  aboutContent.frame = CGRectMake(40, 80, 400, 70);
  myLogo.frame = CGRectMake(230, 30, 20, 20);
  bulletOne.frame = CGRectMake(90, 140, 330, 65);
  bulletTwo.frame = CGRectMake(90, 170, 330, 65);
 } 
 [UIView commitAnimations];
}

在每个UIViewController的视图中,将显示检查设备的方向,如果方向与布局不同,则发送给self。这是假设您的willRotateToInterfaceOrientation:duration:会将布局更新到指定的方向。

我从未使用过ViewWillDisplay…您能详细说明一下吗?ViewWillDisplay会在每次显示VC时被调用,而viewDidLoad只在创建VC(从NIB加载)时被调用一次。因此,当你切换选项卡或在另一个VC出现在屏幕上后返回视图时,实际上每次VC出现在屏幕上之前,它都会收到一条VIEWWILLEXPEND消息。