2014-12-19 19 views
1

我不得不问这个问题,因为我完全被这个机制所困惑。我试图检查纵向方向,虽然它在我的情况下可以在viewdidload中正常工作,但因为我只需要打一次电话,所以我仍然想知道如果每次设备返回时都需要检查肖像,该怎么办肖像。viewDidLayoutSubviews:和UIInterfaceOrientationIsPortrait

我有以下代码

-(void)viewDidLayoutSubviews{ 
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){ 
    self.adviceLabel.preferredMaxLayoutWidth = [[UIScreen mainScreen]bounds].size.width-25; 
    [self.adviceLabel setFrame:CGRectMake(0, 0,[[UIScreen mainScreen]bounds].size.width-25 , 103)]; 
    NSLog(@"portrait"); 
} 

首先“肖像”的被爱过的3倍,我想是因为我有我的VC里面3次,咄。但是当我开始转动屏幕时,实际上我开始一直记录“肖像”,当我“转向风景”时意味着它在我打开风景模式后记录下来。这背后有什么意思吗?我讨厌留下一个不明白的话题。提前致谢!以下为你的目标代码

回答

0

用途:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
// do something before rotation 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
// do something after rotation 
} 

-viewDidLayoutSubviews方法被调用每当视图和它的子视图改变它们的帧。每次视图改变其框架时,检查方向并不是一个好习惯。

+0

你也可以添加方向标志来检查它在任何你想要的。 – 2014-12-19 14:08:28

+0

你的定位标志是什么意思?关于你的答案,我不能使用这些方法,因为我的确在寻找使用UIInterfaceOrientationIsPortrait,但我不明白为什么它在viewdidlayoutsubjects旋转到横向时返回true。 (在其他方法,如viewdidload它按预期工作..) – DevilInDisguise 2014-12-19 14:29:29

+0

您可以添加布尔属性为例。 @property(nonatomic,assign)BOOL viewOrientation。并在上面的方法中进行更改。 – 2014-12-19 14:47:02

相关问题