当我从leftBarButtonItem调整UISearchBar的大小时,我正在尝试添加一个简单的动画。 出于某种原因,虽然searchBar的大小已被修改,但调整大小不会生成动画。但是,如果我尝试修改searchBar的alpha,它会进行动画处理。
这是代码
UISearchBar *baseSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:baseSearchBar];
动画方法是:
[UIView animateWithDuration:2.0f animations:^{
searchBar.frame = CGRectMake(0, 0, 400, 40);
searchBar.alpha = 0;
} completion:^(BOOL finished) {
}];
正如我所说,调整大小的工作,但没有动画,如果我试图改变阿尔法,动画就可以工作。
还有一件事......我试图为rightBarButtonItem做同样的事情并且动画工作..
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(expandWithAnimation:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Test" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 50, 40);
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
提前谢谢