UITextField - 未设置新帧(动画时)

时间:2013-08-14 13:45:24

标签: ios objective-c cocoa-touch uitextfield uisearchbar

我想,将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;没有结果

1 个答案:

答案 0 :(得分:0)

尝试以下块:

   [UIView animateWithDuration:3.0
                          delay:0
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^{
                         CGRect targetFrame =  CGRectMake(-50, 0, 200, 30);
                         searchField.frame = targetFrame; 
                     }
                     completion:^(BOOL finished) {

   }];