我有一个带有遮罩图像的svg,图像是动画gif。 然后我使用TweenlineLite在屏幕上移动它。除了safari之外,这在所有浏览器中都可以正常工在safari中,它在屏幕上动画,但动画gif不起作用!但是,如果我将svg的初始位置更改为屏幕上的gif动画。
任何想法这个safari bug是什么?这是代码heroku deploy log is here
的代码import UIKit
class ViewController: UIViewController,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
@IBOutlet weak var collectionView: UICollectionView!
var images = ["apple","banana","cherry","grapes","kiwifruit","mangoes","orange","papaya","passionfruit","peaches","pineapple","strawberry","sugarapple","watermelon"]
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(orientationChanged(notification:)), name: Notification.Name.UIDeviceOrientationDidChange, object: nil)
collectionView.dataSource = self
collectionView.delegate = self
}
func orientationChanged(notification: Notification) {
collectionView.collectionViewLayout.invalidateLayout()
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return images.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "stridentifier",for:indexPath) as! FruitsCollectionViewCell
cell.image.image = UIImage(named: images[indexPath.row])
cell.nameLabel.text = images[indexPath.row]
return cell
}
class SampleCollectionViewFlowLayout: UICollectionViewFlowLayout {
override init() {
super.init()
setUpLayout()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setUpLayout()
}
override var itemSize: CGSize {
set {}
get {
let itemWidth = ((self.collectionView?.bounds.width)! / 3.0) - self.minimumLineSpacing - minimumInteritemSpacing
return CGSize(width: itemWidth, height: itemWidth)
}
}
func setUpLayout() {
minimumInteritemSpacing = 0
minimumLineSpacing = 1.0
scrollDirection = .vertical
}
override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
return true
}
}
}
答案 0 :(得分:0)
我发现了一个绕过这个问题/ bug的方法。
使用相同的动画gif文件设置标记,并使尺寸为1 x 1
e.g
<img src="resources/images/raven.gif" width="1" height="1">
然后,您可以在屏幕上制作动画并仍然可以播放GIF