我想在UISearchBar
的底部添加UINavigationBar
,我想让它看起来像是酒吧的一部分。在下面的视频中,它显示了导航栏从顶部滑入视图的默认动画。我想在此之前在搜索栏中滑动并使其看起来像一个对象。
如何为显示和隐藏动画的UISearchBar
重新创建此动画?并使其无缝动画?
答案 0 :(得分:0)
我认为您使用导航栏的自定义动画而不是默认动画。
我的测试代码如下。
#import "ViewController.h"
@interface ViewController ()
// Add a UISearchBar below navigation bar in Interface Builder
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@end
@implementation ViewController{
// this is flag for navigation bar status (shown or hidden)
BOOL _isNaviBarHidden;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_isNaviBarHidden = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// trigger for show navigation bar. I don't know when you want to show. so I add a button in my test viewcontroller
- (IBAction)showNavibar:(id)sender {
if(_isNaviBarHidden == NO){
return;
}
[self setNavibarAndSearchBarHidden:NO];
}
- (IBAction)hideNavibar:(id)sender {
if(_isNaviBarHidden == YES){
return;
}
[self setNavibarAndSearchBarHidden:YES];
}
-(void)setNavibarAndSearchBarHidden:(BOOL)hidden{
CGFloat yOffset = -130;
CALayer *naviBarLayer = self.navigationController.navigationBar.layer;
CALayer *searchBarLayer = self.searchBar.layer;
[UIView animateWithDuration:0.3 animations:^{
if(hidden){
naviBarLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMakeTranslation(0, yOffset));
searchBarLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMakeTranslation(0, yOffset));
}else{
naviBarLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformIdentity);
searchBarLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformIdentity);
}
} completion:^(BOOL finished) {
_isNaviBarHidden = hidden;
}];
}