Я включил эффект свечения в свои UIButtons (код, взятый из https://github.com/bc-oscar/Glowing-UIButton). Код находится в отдельном быстром файле, и кнопки определены в контроллере представления как тип «GlowingButton» и изменены для получения этого пользовательского класса в инспекторе идентификации. Эффект работает, когда приложение запускается в первый раз, но затем останавливается при возврате к нему после выхода?animateWithDuration() останавливается после выхода приложения
import UIKit
class GlowingButton: UIButton {
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
*/
// Creates a glow effect in the button by setting its layer shadow properties
func startGlowWithCGColor (growColor:CGColor) {
self.layer.shadowColor = growColor
self.layer.shadowRadius = 10.0
self.layer.shadowOpacity = 1.0
self.layer.shadowOffset = CGSizeZero
self.layer.masksToBounds = false
// Autoreverse, Repeat and allow user interaction.
UIView.animateWithDuration(1.0, delay: 0, options: [UIViewAnimationOptions.Autoreverse, UIViewAnimationOptions.CurveEaseInOut, UIViewAnimationOptions.Repeat, UIViewAnimationOptions.AllowUserInteraction],
animations: {() -> Void in
// Make it a 15% bigger
self.transform = CGAffineTransformMakeScale(1.15, 1.15)
}) { (Bool) -> Void in
// Return to original size
self.layer.shadowRadius = 0.0
self.transform = CGAffineTransformMakeScale(1.0, 1.0)
}
}
// Removes the animation
func stopGlow() {
self.layer.shadowRadius = 0.0
self.transform = CGAffineTransformMakeScale(1.0, 1.0)
self.layer.removeAllAnimations()
self.layer.masksToBounds = true
}
}
Я создал функцию 'viewDidAppear' и поместил там вызовы' button.startGlowWithCGColor', но это все еще не сработало. – Tim
Ни ответ, ни комментарий не помогли мне до сих пор. – Tim