animationbuttonAllowuserinteraction不起作用

我在一个NSObject类的代码中创build了一个UIbutton控制UIViewController类中的游戏。 该button在整个游戏大部分时间都可以正常工作,但是在某个时候,我希望button淡出/淡出。 一旦淡入淡出开始animationbutton不再是互动的。 我已经设置了.AllowUserInteraction选项,但仍然没有运气。 我被困在这一个,所以任何帮助非常感谢!

Class GameController: NSObject { var gameView: UIView! var nextButton: UIButton! func gameViewSetUp() { // create the nextButton let imageNextButton = UIImage(named: "rightArrow") as UIImage? self.nextButton = UIButton(type: .Custom) nextButton.frame = CGRectMake(ScreenWidth-100,ScreenHeight-250,60,60) nextButton.setTitle("", forState: UIControlState.Normal) nextButton.setImage(imageNextButton, forState: .Normal) nextButton.contentMode = .ScaleAspectFill nextButton.backgroundColor = UIColor.clearColor() nextButton.layer.cornerRadius = 5.0 nextButton.layer.borderWidth = 2.5 nextButton.layer.borderColor = UIColor.clearColor().CGColor nextButton.addTarget(self, action: "nextPressed", forControlEvents: .TouchUpInside) nextButton.userInteractionEnabled = true gameView.addSubview(nextButton) func playStageX() { nextButtonWink() } } func nextButtonWink() { UIView.animateWithDuration(1.5, delay: 0, options: [.AllowUserInteraction, .Repeat, .CurveEaseInOut, .Autoreverse], animations: { // self.nextButton.userInteractionEnabled = true // I tried this as well but no impact. self.nextButton.alpha = 0 }, completion: nil) } class GameViewController: UIViewController { private var controller: GameController required init?(coder aDecoder: NSCoder) { controller = GameController() super.init(coder: aDecoder) } override func viewDidLoad() { super.viewDidLoad() let gameView = UIView(frame: CGRectMake(0, 0, ScreenWidth, ScreenHeight)) self.view.addSubview(gameView) controller.gameView = gameView 

}

拿出self.nextButton.alpha = 0来testing这一点,我相信,button事件不会触发时,alpha为零。 当涉及到animation时,animation开始之前,实际的对象的alpha将被设置为零,而你所看到的就像是一个渲染的视图的交互式截图,因为它的animation

如果是这样的话,那么你需要将alpha设置为0.0100000003之类的值,或者覆盖button在alpha 0处进行交互

Swift 3 Xcode 8:

AllowUserAction现在被弃用allowUserAction ….去图

 func nextButtonWink() { UIView.animateWithDuration(1.5, delay: 0, options: [.allowUserInteraction, animations: {