【问题标题】:UITextField - not set new frame (at animation)UITextField - 不设置新帧(在动画中)
【发布时间】:2013-08-14 13:45:23
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    试试下面的块:

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

    【讨论】:

      猜你喜欢
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多