无法为UISearchBar的框架或边界设置动画

我想为UISearchBar的位置设置动画,但是当我更改UISearchBar的帧或边界属性(中心,alpha剂量动画)时,没有动画效果。
这是iOS SDK 4.2,有没有错误? 我很困惑…

问题是一些内部搜索栏视图强制resize以忽略动画。

这对我有用 –

[UIView animateWithDuration:0.2 animations:^ { [searchBar setFrame:searchBarFrame]; [searchBar setNeedsLayout]; }]; 

searchBarFrame – 你需要设置的帧(我在搜索栏第一次resize之前保存它)

使用UIViewAnimationOptionLayoutSubviews选项:

 [UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionLayoutSubviews animations:^{ CGRect frame = searchBar.frame; frame.size.width = newWidth; searchBar.frame = frame; } completion:nil ]; 

尝试这个:

 [UIView animateWithDuration:0.3 animations:^{ self.searchDisplayController.searchBar.frame = CGRectMake(0, 200, 320, 44); }];