我正在尝试使用以下代码对搜索栏的显示/隐藏进行动画处理(搜索栏应从左侧开始并在 1-2 秒内向右扩展)。但是,无论我投入多少时间,它都不会设置动画,并且会立即显示 searchBar。我注意到以下内容:
- 不尊重持续时间
- 甚至不尊重延迟
动画没有发生。组件立即显示
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。我见过其他解决方案,但它们都不适合我。请帮助...
更新:它使用下面的代码。但是,它使用了默认动画选项UIViewAnimationOptionCurveEaseInOut
和TransitionNone
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
})