我已經嘗試了這一點,並確定tabBarController會自動調整其觀點和任何時候會出現以下情況取消所有更改:中selectedViewController變化
- 值;
- 界面方向的變化;
- 標籤欄被重新加載並放置在視圖/窗口中。
我能夠強制UITabBar的視圖保持恆定的大小,通過註冊所有上述事件,然後從它們調用自定義調整大小的方法。
您可以觀察更改selectedViewController與國際志願者組織,就像這樣:
[tabBarController addObserver:self forKeyPath:@"selectedViewController" options:NSKeyValueObservingOptionNew context:NULL]
的接口方向觀察的變化可以是一個有點棘手。如果您是通過應用程序委託或另一個專用於此目的的對象執行此操作,那麼很可能您沒有獲取用於交易方向更改的標準UIViewController回調。有兩種方法可以解決這個問題:(1)UIDevice和通知,以及(2)讓您的一個視圖控制器生成回調。就個人而言,我會推薦後者,因爲UIDevice通知往往會與接口同步幾微秒,並且結果可能看起來很糟糕。簡化的實現:
// In a header somewhere (Prefix.pch works).
extern NSString *const kOrinetationNotification;
extern NSString *const kOrinetationNotificationOrientationKey;
// in an instance of UIViewController
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[[NSNotificationCenter defaultCenter] postNotificationName:kOrientationNotification object:self userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:toInterfaceOrientation] forKey:kOrientationNotificationOrientationKey]];
// do other stuff
}
// in your application delegate's (or other dedicated object) init method
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:kOrientationNotification object:nil];
這應該確保您每次觸發標籤欄的幾何圖形中的某個變化時都會擡頭。一旦你收到這些回調,你可以調用你自己的自定義方法,並調整標籤欄的大小,因爲你認爲合適,不需要繼承它。
謝謝你,我會試一試,看看它是否有效! – 2009-12-04 10:00:50