应该改变错误的价值

时间:2010-10-21 13:48:23

标签: iphone objective-c

我只是尝试在我的shouldautorotate方法中添加一些打印语句,并注意到它检查了4次哪个有意义,但即使我没有从纵向切换到横向模式,

它返回肖像3次,第四次返回景观,即使我的模拟器不在风景中。

if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
   NSLog(@"landscape left");
  }else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
   NSLog(@"landscape right");
  }else if(interfaceOrientation == UIInterfaceOrientationPortrait){
   NSLog(@" portrait");
  }else if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
   NSLog(@"portrait upsidedown");
  }

任何人都知道为什么?

1 个答案:

答案 0 :(得分:1)

尝试将该代码放入didAutorotatewillAutorotate方法。 shouldAutorotate只应返回YES或NO。

我理论上定期检查shouldAutorotate,而didAutorotate仅在检测到方向转换时被触发。

这是我用来检查的代码:

- (void) reOrient{
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){  

    } else {

    }
}

这是我创建的名为reOrient的方法,该方法是从didAutorotate

调用的
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    [self reOrient];
}

只需确保在创建一个像reOrient这样的新方法时,你也可以在标题中声明它(我一直忘记在开始时),如下所示:

- (void)reOrient;
相关问题