小编Okz*_*pes的帖子

使用 SwiftUI 制作按钮闪烁动画

如何在 SwiftUI 中制作边框颜色变化动画。这是 UIKit 的代码

extension UIButton{
    func blink(setColor: UIColor, repeatCount: Float, duration: Double) {
        self.layer.borderWidth = 1.0
        let animation: CABasicAnimation = CABasicAnimation(keyPath: "borderColor")
        animation.fromValue = UIColor.clear.cgColor
        animation.toValue = setColor.cgColor
        animation.duration = duration
        animation.autoreverses = true
        animation.repeatCount = repeatCount
        self.layer.borderColor = UIColor.clear.cgColor
        self.layer.add(animation, forKey: "")
    }
}
Run Code Online (Sandbox Code Playgroud)

xcode animation ios swift swiftui

10
推荐指数
3
解决办法
1万
查看次数

来自Combine 的.sink 方法不适用于iOS 13.3

当变量值改变时,我使用 sink 方法调用函数。代码适用于 iOS 13.2.2 但不适用于 iOS 13.3。当 segmentedSelected 变量改变时,函数 segmentedChanged 不会被调用。

public class ChooseViewModel: ObservableObject {

    @Published var segmentedSelected = Int()


    init() {
        _ = $segmentedSelected
                .debounce(for: .seconds(0.1), scheduler: DispatchQueue.main)
                .sink(receiveValue: self.segmentedChanged(indexValue:))

    }

    func segmentedChanged(indexValue segIndex: Int) {
      print(segIndex)
    }

}
Run Code Online (Sandbox Code Playgroud)

xcode ios swiftui combine ios13.3

4
推荐指数
1
解决办法
1697
查看次数

标签 统计

ios ×2

swiftui ×2

xcode ×2

animation ×1

combine ×1

ios13.3 ×1

swift ×1