![](/img/trans.png)
[英]How to animate a UIView going off the screen to the right, and then reappearing back from the left
[英]Animate View Off-Screen To The Right and Back In From the Left
我正在嘗試復制在此處看到的Apple App Store中找到的動畫。 應用程序圖標像輪播一樣從左到右連續移動,而我正在嘗試為單個UIView產生相同的行為。 有人可以幫助嗎? 真的很掙扎:
我嘗試了一些操作,但停止並重復了動畫,而沒有從左到右繼續。
UIView.animateKeyframes(withDuration: 5, delay: 0, options: .repeat, animations: {
viewOfImageViews.center.x += container.bounds.width +
}, completion: nil)
這是一種可以存檔此效果的方法:
現在在代碼中,當集合被加載時,您滾動到第一部分
DispatchQueue.main.async { self.collView.scrollToItem(at: IndexPath(item: 0, section: 1), at: .left, animated: true) }
現在,您可以在下面添加此代碼,以便在完成動畫后更新單元格並再次滾動
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) { colors.append(colors.removeFirst()) collView.reloadData() DispatchQueue.main.async { self.collView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .left, animated: false) self.collView.scrollToItem(at: IndexPath(item: 0, section: 1), at: .left, animated: true) } }
將顏色數組更改為包含圖像的數組名稱
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.