2011-12-12 171 views
0

我有两个观点将其命名为具有纵向和横向上的旋转,我想切换views.But当负载它工作正常,但在旋转它不是working.please电话我来解决这个问题视图之间切换

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     self.view = self.portrait;  
    } 
    else 
    { 
     self.view = self.landscape; 
    } 
} 
+0

你设置支持的接口方向? –

+0

下次,请在此处放置代码时遵循正确的代码缩进指南。感谢您的时间。 –

+0

@理查德·J·罗斯三亚我有 – crazy2431

回答

0

您必须实现

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

功能在你的MainViewController类,使自转的工作。看看它的参考:Reference Documentation on ViewControllers

你可以简单地说(支持所有方向):

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 
+0

该方法也被添加。 – crazy2431

+0

但你把它放在哪里? – ThomasM

+0

在上面的代码中它不存在..但在我的项目中,我已经添加了上述方法 – crazy2431

0

假设你有你的项目设置中设置了支撑取向,你可以这样做:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

添加这将使视图控制器的权限实际上影响您在willRotateToInterfaceOrientation中所做的更改。

另外,尝试使用此代码视图之间切换:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
    duration:(NSTimeInterval)duration { 
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || 
     toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
     [UIView transitionFromView:self.view 
         toView:self.portrait 
         duration:0.7 
         options:UIViewAnimationOptionTransitionFlipFromLeft 
        completion:^(BOOL finished){ 
         //do something when done with animation 
         }]; 
    } else { 
     [UIView transitionFromView:self.view 
         toView:self.landscape 
         duration:0.7 
         options:UIViewAnimationOptionTransitionFlipFromLeft 
        completion:^(BOOL finished){ 
         //do something when done with animation 
         }]; 
    } 
}