Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS动画在iOS 11.0及以上版本上运行完美,但在iOS 11.0以下版本上出现问题_Ios_Swift_Animation_Constraints - Fatal编程技术网

iOS动画在iOS 11.0及以上版本上运行完美,但在iOS 11.0以下版本上出现问题

iOS动画在iOS 11.0及以上版本上运行完美,但在iOS 11.0以下版本上出现问题,ios,swift,animation,constraints,Ios,Swift,Animation,Constraints,在这里,我附加了我创建的代码来制作动画 class GIFView: UIView { @IBOutlet var firstViewHeight: NSLayoutConstraint! @IBOutlet var secondView: UIView! @IBOutlet var firstView: UIView! var objLabel:LabelView? override func draw(_ rect: CGRect) {

在这里,我附加了我创建的代码来制作动画

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及以上版本上运行完美,但在iOS 11.0以下版本上出现了一些问题,我不明白,如果有人知道解决方案,请给我建议修复它
谢谢。

有没有想过关键帧动画?将动画中的零件移动到完成位置,在该位置设置动画的第一个视图高度,并在其之前。我在这里有一个预感,但我怀疑问题在于您的自动布局动画。在iOS中,引入了11个安全区域,并且往往存在与iOS 10及以下设备的向后兼容性问题。如果你能更具体地描述你所看到的问题,这将有助于那些可能有答案的人。