在这里,我附上了我创建的代码来制作动画,
class GIFView: UIView {
@IBOutlet var firstViewHeight: NSLayoutConstraint!
@IBOutlet var secondView: UIView!
@IBOutlet var firstView: UIView!
var objLabel:LabelView?
override func draw(_ rect: CGRect) {
super.draw(rect)
}
func gifDemo(name:String) {
let animation = LOTAnimationView(name: name)
secondView.contentMode = .scaleAspectFit
animation.frame.size.width = secondView.frame.size.width
animation.frame.size.height = secondView.frame.size.height
secondView.addSubview(animation)
animation.play()
}
func preparelbl(name:String,points:String){
registerXIB()
objLabel?.prepareLabels(name: name, points: points)
}
func registerXIB() {
let nib = UINib.init(nibName: "LabelView", bundle: nil)
objLabel = nib.instantiate(withOwner: nil, options: nil)[0] as? LabelView
objLabel?.frame = CGRect.init(x: 0, y: 0, width: firstView.bounds.size.width , height: firstView.bounds.size.height)
firstView.addSubview(objLabel!)
}
func animation(view:UIView) {
UIView.animate(withDuration: 5, animations: {
self.firstView.alpha = 1.0
self.secondView.alpha = 0.0
}) { (isTrue) in
self.secondView.isHidden = true
self.animationFirstView(view:view)
}
}
func animationFirstView(view:UIView) {
self.commonAnimation(duration:0.5,delay:0.0)
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
while self.firstViewHeight.multiplier > 0 {
self.animationWithCompletion(duration:0.3,delay:0.0,view:view)
}
})
}
func commonAnimation(duration:Double,delay:Double){
UIView.animate(withDuration:duration, delay: delay , options: [], animations: {
let mult = self.firstViewHeight.multiplier - 0.5
self.firstViewHeight = self.firstViewHeight.changeMultiplier(multiplier: mult)
self.firstView.layer.cornerRadius = self.frame.height * mult / 2
self.firstView.layoutIfNeeded()
})
}
func animationWithCompletion(duration:Double,delay:Double,view:UIView){
UIView.animate(withDuration:duration, delay: delay , options: [], animations: {
let mult = self.firstViewHeight.multiplier - 0.01
self.firstViewHeight = self.firstViewHeight.changeMultiplier(multiplier: mult)
self.firstView.layer.cornerRadius = self.frame.height * mult / 2
//self.firstView.clipsToBounds = true
self.firstView.layoutIfNeeded()
}) { (isTrue) in
view.isHidden = true
}
}
}
public extension NSLayoutConstraint {
func changeMultiplier(multiplier: CGFloat) -> NSLayoutConstraint {
NSLayoutConstraint.deactivate([self])
let newConstraint = NSLayoutConstraint(
item: firstItem,
attribute: firstAttribute,
relatedBy: relation,
toItem: secondItem,
attribute: secondAttribute,
multiplier: multiplier,
constant: constant)
newConstraint.priority = priority
NSLayoutConstraint.activate([newConstraint])
return newConstraint
}
}
上面的代码在iOS 11.0及更高版本上运行完美,但在11.0以下的iOS版本出现问题我不明白是否有人知道解决方案然后请给我修复它的建议 谢谢。