我想,将searchField变形为targetFrame
。
#1这不是结果:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)bar
{
UITextField *searchField = [bar valueForKey:@"_searchField"];
CGRect targetFrame = CGRectMake(-50, 0, 200, 30);
searchField.frame = targetFrame; //not result
return YES;
}
#2不正确,但转换:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)bar
{
UITextField *searchField = [bar valueForKey:@"_searchField"];
searchField.frame = CGRectMake (10, 0, 200, 50); //must differ from CGRectZero
[UIView animateWithDuration: 3.0
animations: ^{
CGRect targetFrame = CGRectMake(-50, 0, 200, 30);
searchField.frame = targetFrame;
}];
return YES;
}
然后使用#2,searchField开始动画,但是为默认大小(不是targetFrame
)。
我想,searchField转换为targetFrame
。
PS
searchField.autoresizingMask = UIViewAutoresizingNone;
没有结果
答案 0 :(得分:0)
尝试以下块:
[UIView animateWithDuration:3.0
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
CGRect targetFrame = CGRectMake(-50, 0, 200, 30);
searchField.frame = targetFrame;
}
completion:^(BOOL finished) {
}];