UITextField - not set new frame (at animation)

问题传送
I want, that searchField deformation to targetFrame.

#1 This not result:

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)bar
{
    UITextField *searchField = [bar valueForKey:@"_searchField"];
    CGRect targetFrame =  CGRectMake(-50, 0, 200, 30);
    searchField.frame = targetFrame; //not result

    return YES;
}

#2 Incorrect, but transform:

- (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;
}

Then using #2, searchField start animation, but to default size (not to targetFrame).

I want, that searchField transform to targetFrame.

#3 solution

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

   }];
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,493评论 0 23
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,168评论 0 10
  • 2015年12月31日,这是我来到H市的第三天了,我还是没有勇气联系她。 六年前那条聊天记录是我们最后的交集,...
    公子不见阅读 2,662评论 1 0

友情链接更多精彩内容