美文网首页
UITextField - not set new frame

UITextField - not set new frame

作者: faterman | 来源:发表于2018-07-20 20:22 被阅读4次

    问题传送
    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) {
    
       }];
    

    相关文章

      网友评论

          本文标题:UITextField - not set new frame

          本文链接:https://www.haomeiwen.com/subject/xpaqmftx.html