动画后,iOS模拟器重影图像边缘留在屏幕上

问题描述 投票:-1回答:1

我为UIImage添加了spring选项。它在我的手机上运行良好,非常好。有弹性和光滑。但是当我在iOS模拟器上运行它时,它总是在屏幕上留下一些边缘。当我需要将截图上传到App Store时,它就成了问题。

enter image description here

这是我的代码:

let theTile = numberTile
let bounds = theTile.bounds

UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: [.curveEaseInOut, .allowUserInteraction], animations: {
theTile.bounds = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width * 1.2, height: bounds.size.height * 1.2)
}, completion: nil)

这是缩减代码

let theTile = numberTile
let bounds = theTile.bounds

UIView.animate(withDuration: 0.3, delay: 0, options: .allowUserInteraction, animations: {
theTile.bounds = CGRect(origin: bounds.origin, size: self.size)
}, completion: nil)
ios image screen simulator
1个回答
0
投票

试试这个虽然这可能不是你唯一的问题。如果那是一个集合视图,我需要看到你的单元格中的行函数,因为你可能正在加载一个带有开始的边界的单元格。这是一个建议。相反,为变换设置动画。

//to animate larger
UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2,initialSpringVelocity: 10, options: [.curveEaseInOut, .allowUserInteraction], animations: {
        theTile.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
    }, completion: nil)

//animate smaller
UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: [.curveEaseInOut, .allowUserInteraction], animations: {
        theTile.transform = .identity
    }, completion: nil)

如果这是行的单元格中的集合视图,则可能需要检查所选索引,但如果未选择则为def,则需要将变换设置为identity。

编辑:你说这不能解决问题。你在运行什么环境? Mac的类型。我个人认为这是一个代码问题,因为我写了大量的动画代码,从未见过这个bug。这是一个最小的例子,它不会在我的设备或模拟器上创建“鬼层”。如果你能做一个最小的例子,它会有很大的帮助...在那之前,我认为你的代码可能是你的集合视图。

import UIKit

class ViewController: UIViewController {

    lazy var box : UIView = {
        let v = UIView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
        v.backgroundColor = .blue
        v.center = self.view.center
        return v
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .lightGray
        self.view.addSubview(box)
        box.layer.cornerRadius = 8

    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        fireEvent()
        super.touchesBegan(touches, with: event)
    }

    func fireEvent(){
        if box.transform == .identity{
            //to animate larger
            UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2,initialSpringVelocity: 10, options: [.curveEaseInOut, .allowUserInteraction], animations: {
                self.box.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
            }, completion: nil)
        }else{
            //animate smaller
            UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: [.curveEaseInOut, .allowUserInteraction], animations: {
                self.box.transform = .identity
            }, completion: nil)
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.