我有UISearchBar,我希望它可以随时扩展。我有动画像:
[UISearchBar beginAnimations:nil context:NULL];
[UISearchBar setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UISearchBar setAnimationDuration:0.5];
[self.searchBar setFrame:CGRectMake(self.searchBar.frame.origin.x, self.searchBar.frame.origin.y, self.searchBar.frame.size.width +100, self.searchBar.frame.size.height)];
[UISearchBar commitAnimations];
这是有效的,但是它从左向左扩展它,但我希望它从右向左扩展它。我想在界面构建器中做一些事情,你可以从9点开始选择1来扩展它。
我尝试设置
[searchBar.layer setAnchorPoint:CGPointMake(1, 0.5)];
但它不起作用。
马尔科
答案 0 :(得分:1)
您可以执行以下操作:
[UIView animateWithDuration:0.5
animations:^{
[UIView animateWithDuration:1.0 animations:^{
self.searchBar.frame = CGRectMake(self.searchBar.frame.origin.x - 50.0f, self.searchBar.frame.origin.y, self.searchBar.frame.size.width + 50.0f, self.searchBar.frame.size.height);
[self.searchBar layoutSubviews];
}];
}
completion:^(BOOL finished){ }];
这将使右侧坚持并看到左侧的增长。
答案 1 :(得分:0)
您还应该更改UISearchBar的原点以获得所需的效果。例如:
self.searchBar.frame = CGRectMake(self.searchBa.frame.origin.x - YOUR_OFFSET, self.searchBa.frame.origin.y, self.searchBa.frame.size.width + YOUR_OFFSET, self.searchBa.frame.size.height)
。