2011-12-12 167 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 
         }]; 
    } 
}