4

Greetings,

This question does seem to be an ongoing saga in the world of iphone SDK... so heres my contribution...

Had two separate projects from the same template... one semi-works, the other not at all... Please let me explain my steps...

used this basic GL ES template //iphonedevelopment.blogspot.com/2008/12/opengl-project-template-for-xcode.html had to sort out some of the 'Release' configuration but otherwises has eveything I need to add orientation to a GL ES project.

One my first project, did my stuff, then added these methods....

-(BOOL)shouldAutoRotateToInterfaceOrientation .....   
-(void)willRotateToInterfaceOrientation ....
-(void)didRotateFromInterfaceOrientation ....
-(void)willAnimateRotationToInterfaceOrientation ....

And understand what they do (or are trying to do in my case), the (BOOL)should... gets called once when the view controller is created, and returns 'YES'. But after that none of the other methods are called!

So I started from scratch with a blank template (GL ES one from above)...and added minimum to support auto rotation. But this time none of the methods get called!

So I investigated .... //developer.apple.com/iphone/library/qa/qa2010/qa1688.html as it said, I added the GLViewController.view first, then added the GLview as subviews of the application delegate. Nothing!

Then found this //www.iphonedevsdk.com/forum/iphone-sdk-development/44993-how-determine-ipad-launch-orientation.html which states to enable orientation notifications

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

and then subsequently disable them in the view controller... makes sense...did it, nothing...

I think the notifications might be on by default though, since I didn't need to enable them in the first project, yet it still try to verify a orientation (i.e (BOOL)shouldAutoRotate... )...

If any one could help me out it would be greatly appreciated as this issue is driving me insane. Thanks in advance.

The code can be found here ... http://rapidshare.com/files/392053688/autoRotation.zip

N.B These projects avoid nib/xib resources, would like to keep it that way if possible.

P.S iPad device not out where I am so I cannot test on a device yet. Would be nice for it to work on the simulator.

4

2 に答える 2

4

わかりました..別のカップルが壁に頭をぶつけた後、手動でやってみました...ハレルヤ...

これが結果です...これらの2行を追加して、View Controllerが作成されたときに呼び出されるようにします...つまり、-(void)loadViewまたは同等のもので

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selectot(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

(void)should.... を設定すると、YES が返されます。

-(void)shouldRotateToInterfaceOrienation
{
return YES;
}

すべて削除する..

-(void)willRotateToInterfaceOrientation ....
-(void)didRotateFromInterfaceOrientation ....
-(void)willAnimateRotationToInterfaceOrientation ....

これらは必要ありません...

そして、didRotate というメソッドを追加します。

-(void)didRotate:(NSNotification*)notification
{
UIDeviceOrientation oreo = [[UIDevice currentDevice] orientation];
// oreo is our new orientation!
}

基本的に、問題は、beginGeneratingDeviceOrientationNotifications の追加を使用して動作させるために半端な試みを行ったことです。また、オリエンテーション イベントを「キャプチャ」して自分で処理する必要がありました...

理由を知りたい純粋主義者のために?理由がわからない、または理解できない、申し訳ありません...理論的には機能するはずでしたが、実際には機能しませんでした。

于 2010-05-27T11:26:56.167 に答える
0

didRoateToInterfaceOrienataion が常に呼び出されるとは限らないという問題がありました。shouldRotateToInterfaceOrientation は常に呼び出されますが、理由もなくステータス バーが横向きに回転することがありますが、View Controller は回転せず、didRotateTo... は呼び出されませんでした。didRotateTo をサポートするために NavigationController をオーバーライドしようとしましたが、NavigationController のすべてのビューで回転をサポートしたくありませんでした。

最終的に私が決定したのは、回転をサポートするビューよりも前のビューも回転をサポートする必要があるということでした。問題は以前のビューで発生しただけだと思う​​かもしれませんが、どういうわけか問題はなくなり、それが唯一の変更点でした。

これもhttp://developer.apple.com/library/ios/#qa/qa1688/_index.html

于 2011-11-22T23:50:57.040 に答える