2011-06-24 11 views
1

現在、Xcode 4.0.2を使用してiPhoneアプリを作成しています。ユーザーが携帯電話を使用したときに、アプリが画面を切り替えるようにします。たとえば、ユーザーが自分のiPhoneを横に動かすと、iPhoneはあらかじめ作成された横のビューに変わります。私はそれのためのコードを作成しましたが、私はiOSシミュレータでそれを実行し、デバイスを回転させると何も起こりません。私は間違って何をしていますか?iPhoneのインターフェイスオリエンテーション - これは何が問題なのですか?

ヘッダーファイル:

#import "FlipsideViewController.h" 

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate> { 
IBOutlet UIView *portraitView; 
IBOutlet UIView *landscapeView; 

} 
@property (nonatomic, retain) UIView *portraitView; 

@property (nonatomic, retain) UIView *landscapeView; 

@end 

実装ファイル(.M):

#import "MainViewController.h" 
#define deg2rad (3.1415926/180.0) 

@implementation MainViewController 
@synthesize portraitView; 
@synthesize landscapeView; 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Return YES for supported orientations. 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
    self.view=landscapeView; 
    self.view.transform=CGAffineTransformMakeRotation(deg2rad*(90)); 
    self.view.bounds=CGRectMake(0.0, 0.0, 480.0, 320.0); 
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { 
    self.view=landscapeView; 
    self.view.transform=CGAffineTransformMakeRotation(deg2rad*(-90)); 
    self.view.bounds=CGRectMake(0.0, 0.0, 480.0, 320.0); 
} else { 
    self.view=portraitView; 
    self.view.transform=CGAffineTransformMakeRotation(deg2rad*(0)); 
    self.view.bounds=CGRectMake(0.0, 0.0, 300.0, 460.0); 
} 

[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

} 

@end 

私は必要ないいくつかのことを取り出しているので、.mファイルは少し裸に見えるかもしれ。私はIBOutlets landscapeViewとportraitViewを、MainViewController.xibという1つの.xibファイル内の2つの異なるビューにリンクしました。

私がビルドするとき、エラー、警告、またはシグナルはありません。

これを行う簡単な方法はありますか、間違っているだけですか?誰かが助けてくれましたか? ありがとうございます!

答えて

3

shouldAutorotateToInterfaceOrientationを修正する必要があります。戻り値は常に、それがより

Xcodeの程度迷惑なものの一つだ
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Return YES for supported orientations. 
    return (interfaceOrientation == UIInterfaceOrientationPortrait) 
     || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
     ||(interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 
+0

のようになります、最初に一致します、それが到達不能またはデッドコードを警告しません、あなたの第二2つのreturn文は、到達不能でした機能が最初に当たると機能が終了するので、 –

+0

うわー、ありがとう!あなたは素晴らしいです!それは今や理にかなっていて、うまくいきます!ありがとう! –

関連する問題