我正在做一個應用程序,我改變按鈕佈局取決於如果用戶在縱向與橫向模式中移動他的iphone。我認爲把我的代碼的最佳地點是在最好的方法來檢測iphone方向
-(BOOL) shouldautorotatetointerfaceorientation
但也有與
當頁面加載shouldautorotatetointerfaceorientation兩大問題被稱爲至少3倍。我只想執行一次我的代碼。
即使當我從viewController1(page1)移動到viewController2(page2)與Modal segue,我旋轉我的iphone在page2它仍然調用自動代碼,這是我的viewcontroller1。這很奇怪。
總之,什麼是最好的地方把我的方向爲基礎的圖標?
...或'willAnimateRotationToInterfaceOrientation',這往往是非常有用的,因爲你把這個方法中的任何代碼(如適用)動畫也很容易。 – lxt 2012-01-11 21:34:13
我只是用這個和apprently我需要添加[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate :) name:@「UIDeviceOrientationDidChangeNotification」object:nil];隨着didRotate函數和didRotate我會知道用戶是否在縱向或橫向模式下移動設備? – 2012-01-11 21:42:13
@SamBudda你不需要註冊上面列出的方法的默認值。但是,如果您想要爲任何設備方向更改觸發自定義方法'didRotate',則應添加您提到的通知。 – PengOne 2012-01-11 21:51:47