我的导航栏中有一个自定义的后退按钮。 当键盘出现时,我只需用关闭按钮替换后退按钮。 当键盘关闭时,我恢复后退按钮。
这是我用来设置左导航按钮的功能:
-(UIBarButtonItem*)configureLeftButtonWithImageName:(NSString*)imageName
target:(id)target
action:(SEL)action
{
UIButton *accountButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttImage = [UIImage imageNamed:imageName];
[accountButton setImage:buttImage forState:UIControlStateNormal];
float padding = 4;
accountButton.imageEdgeInsets = UIEdgeInsetsMake(padding, 0, padding, 2*padding);
float buttH = kNavigationButtonHeight + 2*padding;
float buttW = buttH;
if( buttImage )
{
buttW = buttH * buttImage.size.width / buttImage.size.height;
}
accountButton.bounds = CGRectMake(padding, padding, buttW, buttH);
[accountButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:accountButton];
[self.navigationItem setLeftBarButtonItem:barButtonItem];
return barButtonItem;
}
我在这里切换:
-(void)kbDidAppear
{
[self configureLeftButtonWithImageName:@"quit" target:self action:@selector(hideKb:)];
}
-(void)kbDidDisappear
{
[self configureLeftButtonWithImageName:@"back" target:self action:@selector(navigationBack:)];
}
但是当使用退出按钮替换后退按钮时,会播放不需要的动画:
退出按钮出现在导航栏的左上角,然后将该位置设置为正常值......
当我从退出按钮切换到后退按钮时,问题不会出现!
答案 0 :(得分:0)
我刚刚找到了解决方法,我正在从返回按钮切换到退出按钮 UIKeyboardWillShowNotification 回调,如果我在 UIKeyboardDidShowNotification 回调中进行回调,不再有奇怪的动画