1

我想要,那个 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.

附言

searchField.autoresizingMask = UIViewAutoresizingNone;不是结果

4

1 回答 1

0

试试下面的块:

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

   }];
于 2013-08-14T14:03:28.887 回答