OS3.0のshouldAutorotateTo-InterfaceOrientationがおかしい件

Posted by: daichi  /  Category: iphone開発

OS3.0に変わってshouldAutorotateToInterfaceOrientationとその近辺の挙動が変わっている。shouldAutorotateToInterfaceOrientationをオーバーライドして独自処理を実装している場合は、動作をOS3.0で確認することをおすすめします。

今確認できているのは以下の2つ
・shouldAutorotateToInterfaceOrientationが呼ばれるタイミング
・shouldAutorotateToInterfaceOrientationが呼ばれる回数



最終的にshouldAutorotateToInterfaceOrientationを使わず加速度センサで向きを切り替えるようにしました。

似たような現象に遭遇してる人がいたので、めちゃめちゃ参考にしてます。
iPhone OS 3.0 – Breaking changes to shouldAutorotateToInterfaceOrientation | blog.sallarp.com
Find the device orientation using the accelerometer | blog.sallarp.com

加速度センサのX,Y成分から端末の傾いている向きを判定する方法。
上のリンクの人のコードだと、ちょっと傾きがおかしかったりしたので数値を少し直してます。

?View Code OBJECTIVE-C
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
	// 本体の向きから傾きを取得
	float xx = -[acceleration x];
	float yy = [acceleration y];
	float angle = atan2(yy, xx); 
 
	// ホームボタンが下にある判定
	if(angle >= -2.25 && angle <= -0.75)
	{
		if(deviceOrientation != UIInterfaceOrientationPortrait)
		{
			deviceOrientation = UIInterfaceOrientationPortrait;
			[self flip];
		}
	}
	// ホームボタンが右にある判定
	else if(angle >= -0.75 && angle <= 0.75)
	{
		if(deviceOrientation != UIInterfaceOrientationLandscapeRight)
		{
			deviceOrientation = UIInterfaceOrientationLandscapeRight;
		}
	}
	// ホームボタンがに上ある判定
	else if(angle >= 0.75 && angle <= 2.25)
	{
		if(deviceOrientation != UIInterfaceOrientationPortraitUpsideDown)
		{
			deviceOrientation = UIInterfaceOrientationPortraitUpsideDown;
		}
	}
	// ホームボタンが左にある判定
	else if(angle <= -2.25 || angle >= 2.25)
	{
		if(deviceOrientation != UIInterfaceOrientationLandscapeLeft)
		{
			deviceOrientation = UIInterfaceOrientationLandscapeLeft;
		}
	}
}


このコードではホームボタンが下にきた時に元の画面へ戻すメソッドを読んでます。
呼び出し元、呼び出し先の両方でこの方法を使って無限ループ脱出しました。

というか、これけっこう致命的な変更な気がするんだけど、他にけっこう影響出るんじゃないだろうか。
他にもいろいろあるのかも。僕のアプリはこれだけっぽかったのでひとまずこれで申請予定。

関連のあるアプリ

islot_icon
iSlot Pro 2009/03/13 リリース
ファイナンス 350円
パチスロ収支管理アプリ
app_store_badge

タグ: iphone, iSlot, iSlot Pro, objecti, objective-c, OS 3.0, アプリ, パチスロ, リリース, 収支

関連する投稿

2 Responses to “OS3.0のshouldAutorotateTo-InterfaceOrientationがおかしい件”

  1. 岸川克己 Says:

    UIDeviceOrientationDidChangeNotificationを使うのも簡単ですよ。エントリー書きました。
    http://d.hatena.ne.jp/KishikawaKatsumi/20090510/1241968017

  2. daichi Says:

    >岸川克己さん
    なるほど。Notificationでやる方が確かにシンプルに実装できますね。勉強になります。参考にさせていただきます。

コメント

Additional comments powered by BackType

Get Adobe Flash playerPlugin by wpburn.com wordpress themes