我在网上搜索了很长时间。但没用。请帮助或尝试提供一些如何实现这一点的想法。
在View Controller中创建一个UIViewX 在自定义视图(UIViewX)上添加UIButton。并且IBAction是打印(“测试”)
一切都很好。
但是...
在自定义视图(UIViewX)上添加UIButton并使用UIViewX添加动画代码时,如果按下它,按钮不起作用
如何修复它可以响应打印(“测试”)?
提前致谢。
这是动画代码:
var currentColorArrayIndex = -1
var colorArray:[(color1: UIColor, color2: UIColor)] = []
override func viewDidLoad() {
super.viewDidLoad()
colorArrayFunction()
backgroundAnimate()
}
colorArrayFunction & backgroundAnimate
这是UIViewX代码:
import UIKit
@IBDesignable
class UIViewXXXXX: UIView {
// MARK: - Gradient
@IBInspectable var firstColor: UIColor = UIColor.white {
didSet {
updateView()}}
@IBInspectable var secondColor: UIColor = UIColor.white {
didSet {
updateView()}}
@IBInspectable var horizontalGradient: Bool = false {
didSet {
updateView()}}
override class var layerClass: AnyClass {
get {
return CAGradientLayer.self}}
func updateView() {
let layer = self.layer as! CAGradientLayer
layer.colors = [ firstColor.cgColor, secondColor.cgColor ]
if (horizontalGradient) {
layer.startPoint = CGPoint(x: 0.0, y: 0.5)
layer.endPoint = CGPoint(x: 1.0, y: 0.5)
} else {
layer.startPoint = CGPoint(x: 0, y: 0)
layer.endPoint = CGPoint(x: 0, y: 1)
}}
// MARK: - Border
@IBInspectable public var borderColor: UIColor = UIColor.clear {
didSet {
layer.borderColor = borderColor.cgColor}}
@IBInspectable public var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth}}
@IBInspectable public var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
}
}
// MARK: - Shadow
@IBInspectable public var shadowOpacity: CGFloat = 0 {
didSet {
layer.shadowOpacity = Float(shadowOpacity)}}
@IBInspectable public var shadowColor: UIColor = UIColor.clear {
didSet {
layer.shadowColor = shadowColor.cgColor}}
@IBInspectable public var shadowRadius: CGFloat = 0 {
didSet {
layer.shadowRadius = shadowRadius}}
@IBInspectable public var shadowOffsetY: CGFloat = 0 {
didSet {
layer.shadowOffset.height = shadowOffsetY}}}