正在尝试在UIbarbuttonItem中设置抽奖动画。是否可以在UIBarButtonItem
只需使用UIBarButtonItem(customView: yourView)
//Initialise a Lottie view with frame
let customAnimationView = AnimationView(name: "yourLottieFileName")
customAnimationView.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
//Do your configurations
customAnimationView.loopMode = .loop
customAnimationView.backgroundBehavior = .pauseAndRestore
//Add a tap gesture
customAnimationView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(closeButtonTapped(_:))))
//And play
customAnimationView.play()
//Initilise a bar button with this custom Lottie view and use it
yourBarButton = UIBarButtonItem(customView: customAnimationView)
navigationItem.setLeftBarButton(yourBarButton, animated: true)
测试了此代码,对我来说很好用。