Skip to content

为什么自定义放大动画时, 第一个tab没法默认放大呀? #311

@hubin97

Description

@hubin97

class RAMScaleAnimation: RAMItemAnimation {

var normalImage: UIImage?
var selectImage: UIImage?

var scaleFactor: CGFloat = 1.3

override func playAnimation(_ icon: UIImageView, textLabel: UILabel) {
    if let selectImage {
        icon.image = selectImage
    }
    textLabel.textColor = textSelectedColor
    icon.transform = CGAffineTransform(scaleX: scaleFactor, y: scaleFactor) // 保持放大
}

/// 取消选中恢复
override func deselectAnimation(_ icon: UIImageView, textLabel: UILabel, defaultTextColor: UIColor, defaultIconColor: UIColor) {
    // 恢复默认 image
    if let normalImage {
        icon.image = normalImage
    }
    textLabel.textColor = defaultTextColor
    icon.transform = .identity
}

/// 初始选中状态,保持放大
override func selectedState(_ icon: UIImageView, textLabel: UILabel) {
    if let selectImage {
        icon.image = selectImage
    }
    textLabel.textColor = textSelectedColor
    icon.transform = CGAffineTransform(scaleX: scaleFactor, y: scaleFactor)
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions