我有一个图像视图,并显示带有点图标的活动屏幕。当用户滚动collectionview来更改页面时,图像视图的x位置设置在所选页面的中心,并且当我按下搜索按钮时,我在屏幕顶部有一个搜索栏,它显示带有动画的搜索栏,但点图像又回到带有动画的第一个布局
这是我的点图像视图动画:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == collectionview {
let x = (scrollView.contentOffset.x / view.frame.width)
if x >= 0.0 && x < 0.5 {
UIView.animate(withDuration: 0.3) {
self.selectedDot.center.x = self.tabMainButton.center.x
self.view.layoutIfNeeded()
}
} else if x == 0.5 {
UIView.animate(withDuration: 0.3) {
self.selectedDot.center.x = self.tabFavoriteButton.center.x
self.view.layoutIfNeeded()
}
} else if x > 0.5 {
UIView.animate(withDuration: 0.3) {
self.selectedDot.center.x = self.tabFavoriteButton.center.x
self.view.layoutIfNeeded()
}
}
}
}
这是搜索栏动画的功能:
@IBAction func searchButtonClicked(_ sender: Any) {
if isSearchActive {
searchBar.endEditing(true)
UIView.animate(withDuration: 0.2) {
self.searchHeight.constant = 0
self.view.layoutIfNeeded()
}
} else {
UIView.animate(withDuration: 0.2) {
self.searchHeight.constant = 56
self.view.layoutIfNeeded()
}
}
self.collectionview.reloadData()
isSearchActive = !isSearchActive
}