簡體   English   中英

在屏幕外向右動畫視圖,從左向后動畫

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM