2017-06-13 12 views
0

我添加bar按钮项到导航项。iOS设置barbuttonitems导航项总是有动画

但我发现我设置了动画NO或YES,barbuttonitems总是从左至右有动画。

如何取消设置条形按钮项目的动画。

我下面的代码:

-(void)viewDidLoad{ 
... 
doneBtn = [[UIBarButtonItem alloc]  initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self  action:@selector(barbuttonDoen)]; 

... 
} 

- (void)keyboardWillShow:(NSNotification *)notification { 

// self.theMenu is using storyboard drag. 

[self.navigationItem setRightBarButtonItems:[[NSArray alloc] initWithObjects:doneBtn, self.theMenu animated:NO]; 

} 

非常感谢你。

+0

您需要设置正确栏按钮的阿尔法不是s和右键。 – KKRocks

+0

如何设置右栏按钮的alpha值以及alpha和animate的关系?谢谢 – dickfala

+0

,因为如果您每次设置了右按钮,那么它都会是混乱的动画,因此您需要设置alpha值。 – KKRocks

回答

0

您需要隐藏并通过alpha属性显示右键。

显示

[self.navigationItem.rightBarButtonItem.customView setAlpha:1.0]; 

隐藏

[self.navigationItem.rightBarButtonItem.customView setAlpha:0.0]; 

动画

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

Hi @KKRocks。我尝试设置[self.navigationItem.rightBarButtonItem.customView setAlpha:0.0]; [self.navigationItem setRightBarButtonItems:[[NSArray alloc] initWithObjects:doneBtn,self.theMenu animated:NO]; 但是,当我在keyboardWillShow上运行时,doneBtn和theMenu仍然显示从左向右移动的动画。我不知道为什么@@ – dickfala

+0

我不想在设置RightBarButtonItems时显示动画。 – dickfala

+0

在keyboardWillShow中仍然使用? self.navigationItem setRightBarButtonItems:[[NSArray alloc] initWithObjects:doneBtn,self.theMenu animated:NO]; – KKRocks