0

我的应用程序出现问题,这让我发疯。在我的应用程序中,我将模拟器旋转到横向模式,但在下面的函数中,我得到纵向。

这里有什么问题?请帮帮我。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
  if ( interfaceOrientation == UIInterfaceOrientationPortrait || 
  interfaceOrientation ==    UIInterfaceOrientationPortraitUpsideDown )
  {
    NSLog(@" portrait orientation");
  }
  else
  {
    NSLog(@"Landscape"); 
  }
 return YES;
}
4

4 回答 4

1

首先设置方向值是方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
NSLog(@"shouldAutorotateToInterfaceOrientation called...");
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIDeviceOrientationPortraitUpsideDown) 
        defaultOrientation = 0;
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        defaultOrientation = 1;
    [self setTheOrientation];
    return YES;

}

现在根据 setTheOrientation 方法中的布尔值设置您需要的坐标值。

于 2010-12-30T06:48:47.817 回答
1

该方法返回 BOOL,您必须返回 YES 或 NO

于 2010-12-30T06:53:19.360 回答
0

为什么你没有返回 BOOL 值?YES 或 NO 告诉操作系统您将处理相应的方向事件。

于 2010-12-30T06:41:15.620 回答
0

如果您想要纵向模式,则在if clouse中添加 return TRUE,如果您想要横向,则在else clouse中添加 return TRUE ,如果您想要两种模式,则只需在 shouldAutoRotate clouse 中键入 return TRUE

于 2010-12-30T06:53:22.477 回答