2013-07-19 37 views
0

我有两个视图(视图1和视图2)。 view1包含一个按钮,当我点击这个按钮,我去查看2.我想显示view2与定位肖像和景观。对于view2,我创建了2个UiviewController,一个用于横向,另一个用于纵向,并且具有相同的Class.but不起作用。任何人有任何想法?定位与故事中的ios 5

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

你为什么要使用2个viewcontrollers一个看法?当用户转动设备时,您也可以将view2旋转到风景。 – wkberg

+0

因为,我的视图没有正确显示 –

回答

0

为什么你需要两个 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; 
} 
+0

抱歉,但我使用两个uiViewController,而不是两个视图。 'self.viewPortrait.hidden = NO; self.viewLandscape.hidden = YES;' –