Can't animate the frame or bounds of a UISearchBar

后端 未结 3 1686
挽巷
挽巷 2020-12-21 01:11

I want to animate the position of a UISearchBar, but there\'s no animate effect when I change the frame or bounds property of UISearchBar(center, alpha dose animate).

3条回答
  •  天涯浪人
    2020-12-21 01:51

    Use the UIViewAnimationOptionLayoutSubviews option:

    [UIView animateWithDuration:.25
                          delay:0
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^{
                         CGRect frame = searchBar.frame;
                         frame.size.width = newWidth;
                         searchBar.frame = frame;
                     } completion:nil
     ];
    

提交回复
热议问题