【问题标题】:orientation with ios 5 in storybord在情节提要中使用 ios 5 进行定位
【发布时间】:2013-07-19 17:36:04
【问题描述】:

我有两个视图(视图 1 和视图 2)。 view1 包含一个按钮,当我单击此按钮时,我转到视图 2。我想显示具有方向纵向和横向的 view2。对于 view2,我创建了 2 个 UiviewController 一个用于横向,第二个用于纵向,并且具有相同的 Class.but 不起作用。有人知道吗?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
     return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

【问题讨论】:

  • 那么你为什么要为一个视图使用 2 个视图控制器呢?您也可以在用户转动设备时将 view2 旋转为横向。
  • 因为我的视图显示不正常

标签: ios orientation landscape


【解决方案1】:

为什么你需要 两个 ViewControllers 只是为了定位..?

这里是简单的场景,

创建 2 个视图

  1. 肖像&&
  2. 横向视图,根据您的要求。

关注这样的事情。

-(BOOL)shouldAutorotate{
    return YES;
}

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self orientationChanged:toInterfaceOrientation];
}

-(void)orientationChanged:(UIInterfaceOrientation)orientation{
    NSLog(@"orientation change");
   // UIDeviceOrientation deviceOrientation = [[object object] orientation];

    if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown){
        NSLog(@"Changed Orientation To Portrait");
        self.viewPortrait.hidden = NO;
        self.viewLandscape.hidden = YES;
    }

else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){
    NSLog(@"Changed Orientation To Landscape");

    self.viewPortrait.hidden = YES;
    self.viewLandscape.hidden = NO;
    }  
}

你应该设置所有需要的方向。

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

【讨论】:

  • 抱歉,我使用两个 uiViewController,而不是两个视图。 self.viewPortrait.hidden = NO; self.viewLandscape.hidden = YES;
猜你喜欢
  • 2011-12-27
  • 1970-01-01
  • 2011-12-07
  • 2011-12-26
  • 2012-09-22
  • 1970-01-01
  • 2013-11-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多