• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

at iPhoneOS 3.1.2

shouldAutorotateToInterfaceOrientationじゃなくて任意のタイミングで roateする方法を探していたんだけど、見かけるのはUIViewのtransformでrotateすることばかり。確かめてないけど。この方法だとUIViewControllerのinterfaceOrientationと齟齬も発生するじゃないかと思う。

それで無理くり何とかする方法を考案した。けど、この方法では(もう少し改善すればできるかもしれないが)重力方向への回転しかできない。 shouldAutorotateToInterfaceOrientation:を使ってrotateすのはいつもとどおり。だけど先に方向を決めておいてNSNotificationを投げて強制的にshouldAutorotateToInterfaceOrientation:を発生させることによって 任意のタイミングでviewを回転させる事ができる。

   1  - (void)rotateNow{
   2    UIDevice *device = [UIDevice currentDevice];
   3    self.toRotate = device.orientation;
   4    NSNotification *notification = [NSNotification notificationWithName:@"UIDeviceOrientationDidChangeNotification" object:device];
   5    [[NSNotificationCenter defaultCenter] postNotification:notification];
   6  }
   7  
   8  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   9    if(self.toRotate){
  10      return interfaceOrient == self.toRotate;
  11    }else{
  12      return NO;
  13    }
  14  }

こんな感じ。何をしたかったかと言うと向きが変わったときにいきなり回転させるんじゃなくて、ちょっとボタンをだして確認を取りたかった。だからタイミングだけずらして回転方向は重力方向だけでいいやって話しなんだけど。

もしかすると、このNSNotificationを作ってる部分でobject:deviceってUIDeviceを渡してる部分。このオブジェクトのプロパティorientationを任意の方向を返す様なオブジェクトを作ってViewControllerを更に騙すことができるならば、タイミングだけじゃなくて方向も変えれるんじゃないかな?そこまでは確認を取ってません。

まぁ何にせよ。かなりhackな方法だからOSのバージョン上がったら使えなくなるかもしれない。

posted by Png bopper on Sun 31 Jan 2010 at 14:02

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1700
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ