2011-05-26 75 views
0

我要上leftBarButtonItem一個自定義動畫:自定義動畫navigationItem

UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] 
           initWithTitle:@"Menu" 
           style:UIBarButtonItemStyleBordered 
           target:self 
           action:@selector(onMenuButtonTouch)]; 
viewController.navigationItem.leftBarButtonItem = menuButton; 

我的UINavigationController推動並彈出一個自定義動畫視圖,以便在leftBarButtonItem沒有目前任何動畫。

[self.navigationController pushViewController:myViewController animated:NO]; 
[UIView animateWithDuration:... 

-

首先我更改的屬性,如果它是動畫,但沒有工作的看到。然後我試圖在動畫開始之前設置屬性,但那也不起作用。這絕對沒有影響。

有沒有辦法讓這樣的東西動畫呢?

self.navigationController.navigationItem.leftBarButtonItem.width = 10; 

self.navigationController.navigationItem.leftBarButtonItem.customView.alpha = 0; 

回答

1

UIBarButtonItem s爲不是UIView子類,所以你可以不適用動畫上他們,但customViewUIView對象,所以你可以激活它。

[UIView animateWithDuration:1.0 
       animations:^{ 
        self.navigationItem.rightBarButtonItem.customView.alpha = 0; 
       }]; 
+0

是的,工作,謝謝。我的錯是我稱爲self.navigationController.navigationItem ...而不是self.navigationItem ... – Robin 2011-05-27 12:03:06