【问题标题】:swift Make UIImageView and UIView like one layer to make them animate togetherswift 使 UIImageView 和 UIView 像一层一样使它们一起动画
【发布时间】:2019-11-19 09:38:53
【问题描述】:

我有一个包含许多层的集合视图单元,希望它们像一层一样相互动画

这是两层,其中一层是图像,另一层是视图

self.contentView.addSubview(ImageView)
self.contentView.addSubview(canvas)
canvas.frame = self.contentView.frame

【问题讨论】:

    标签: swift uiview uiimageview uicollectionviewcell


    【解决方案1】:

    最好把 imageView 和 canvas 放在一个容器视图中,并对其进行动画处理

    【讨论】:

    • 我让它做得更好,但在动画结束时其中一个仍然移动到另一个远
    • 如果两者都占据整个容器框架,则不会发生这种情况
    • 我有很多层,有很多 UIPanGestureRecognizer 这使我的单元格出现更多冲突stackoverflow.com/users/5820010/sh-khan
    【解决方案2】:

    你可以在layoutsubview函数中用画布改变UIImageView中心的框架,或者你可以使用constraintlayout来处理自动移动

    self.contentView.addSubview(ImageView)
    self.contentView.addSubview(canvas)
    
    canvas.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate([
            canvas.topAnchor.constraint(equalTo: self.ImageView.topAnchor),
            canvas.bottomAnchor.constraint(equalTo: self.ImageView.bottomAnchor),
            canvas.leadingAnchor.constraint(equalTo: self.ImageView.leadingAnchor),
            canvas.trailingAnchor.constraint(equalTo: self.ImageView.trailingAnchor)
    ])
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 2022-01-21
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多