2011-12-16 54 views
3

我有以下問題:我已經覆蓋的UINavigationControllerpopViewControllerAnimated:(BOOL)animated,因爲我想有一個自定義動畫。代碼如下:防止UINavigationBar的popViewController動畫

- (UIViewController *)popViewControllerAnimated:(BOOL)animated 
{ 
    UIViewController *poppedCtrl = [super popViewControllerAnimated:NO]; 
    [((customViewController *) self.topViewController) doCustomAnimation]; 
    return poppedCtrl; 
} 

不幸的是,UINavigationBar似乎忽略了我明確的禁止動畫內置而且還在動畫。

我有什麼做的,還可以防止導航欄的動畫?

回答

11

一些閱讀,也有一些實驗,我終於找到了需要做的事情,以達到所期望的行爲是什麼之後。

爲了防止動畫它不足以覆蓋(UIViewController *)popViewControllerAnimated:(BOOL)animated導航欄。

還需要創建一個自定義導航欄和覆蓋(UINavigationItem *)popNavigationItemAnimated:(BOOL)animated

- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated { 
    return [super popNavigationItemAnimated:NO]; 
} 

當然這個自定義導航欄也必須是使用(我剛剛更換其使用的導航條中的一個我的導航控制器在界面生成器中)。

+3

任何理由,這種行爲不也爲pushNavigationItem工作:......? – horseshoe7 2014-01-22 15:59:42

0

如果任何人希望禁用推送動畫 - 這對我的作品,通過對UINavigationBar的overrideing這種方法:

- (void)pushNavigationItem:(UINavigationItem *)item { 
    NSMutableArray* items = [[self items] mutableCopy]; 
    [items addObject:item]; 
    self.items = items; 
}