【发布时间】:2015-11-20 15:33:13
【问题描述】:
我正在尝试使用以下代码对搜索栏的显示/隐藏进行动画处理(搜索栏应从左侧开始并在 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
})
【问题讨论】:
-
你在哪里将搜索栏的 alpha 设置为 0?
-
我怀疑框架更改将在自动布局系统中起作用。
-
Alpha 在 uiview 代码之前设置为零
-
这就是我所指出的,如果您使用自动布局,那么视图的帧更改将不起作用..
-
该死!我的错。为了隐藏,我将
hidden设置为true,后来为了显示它,我使用了alpha。当我在两边都使用 alpha 时,动画开始工作。但是,无论我使用什么动画选项,它总是显示一个动画,好像它是“从中心弹出”
标签: ios swift animation uiviewanimationtransition ios-animations