UiView.animateWithDuration不能animationSwift

我正在尝试使用下面的代码来animation显示/隐藏search栏(search栏应该从左边开始,并在1-2秒内向右扩展)。 但是,无论我投入了多less时间,它都不会立即显示animation和search条。 我注意到下面

  • 持续时间不受尊重
  • 甚至不延迟被尊重
  • animation没有发生。 组件立即显示

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { //code to get selected value... //Hide the collection view and show search bar UIView.animateWithDuration(10.0, delay: 0.0, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: { self.searchBar.hidden = false self.searchBar.frame = CGRectMake(0, 0, 300, 44) //This doesn't work either }, completion: { (finished: Bool) in return true }) } 

我正在使用Xcode 7,iOS 8和Swift 2.0。 我已经看到了其他解决scheme,但没有一个为我工作。 请帮助…

更新 :它使用下面的代码。 但是,它使用了UIViewAnimationOptionCurveEaseInOutTransitionNone默认animation选项

 UIView.animateWithDuration(0.7, animations: { self.searchBar.alpha = 1.0 self.searchBarRect.origin.x = self.searchBarRect.origin.x + 200 self.searchBar.frame = self.searchBarRect }, completion: { (finished: Bool) in return true }) 

在animateWithDuration之前,将XPosition设置为-200,将YPosition设置为-200。

像Danielbuild议的那样,你也需要从1.0以外的东西中改变alpha,以便看到它“淡入”。

你在使用自动布局吗? 如果你是,你可能想要animation的约束,而不是框架。

最后,你确定你已经正确地连接了search栏吗?

编辑:PS,我会保持持续时间像3.0或5.0。 10.0会永远消失,可能会让你觉得它没有做任何事情,因为需要多长时间。 使其3.0或5.0(最大)只是为了testing,然后减less到你想要的地方。