Ios UITextField-未设置新帧(在动画中)
我想,搜索字段变形为Ios UITextField-未设置新帧(在动画中),ios,objective-c,cocoa-touch,uitextfield,uisearchbar,Ios,Objective C,Cocoa Touch,Uitextfield,Uisearchbar,我想,搜索字段变形为targetFrame #1这不是结果: - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)bar { UITextField *searchField = [bar valueForKey:@"_searchField"]; CGRect targetFrame = CGRectMake(-50, 0, 200, 30); searchField.frame = targetFrame; //no
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;
}
- (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不正确,但转换:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)bar
{
UITextField *searchField = [bar valueForKey:@"_searchField"];
CGRect targetFrame = CGRectMake(-50, 0, 200, 30);
searchField.frame = targetFrame; //not result
return YES;
}
- (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
)
我想把搜索字段转换成targetFrame
PS
searchField.autoresizingMask=UIViewAutoResizingOne代码>非结果尝试以下程序块:
[UIView animateWithDuration:3.0
delay:0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
CGRect targetFrame = CGRectMake(-50, 0, 200, 30);
searchField.frame = targetFrame;
}
completion:^(BOOL finished) {
}];