Ios 动画按钮Allowuserinteraction不工作

Ios 动画按钮Allowuserinteraction不工作,ios,swift,animation,uibutton,Ios,Swift,Animation,Uibutton,我在NSObject类的代码中创建了一个UIbutton,它控制UIViewController类中的游戏。在游戏的大部分时间里,这个按钮都可以正常工作,但在某一点上,我希望这个按钮消失。一旦fadein/out开始设置动画,按钮就不再是交互式的。我已经设置了.AllowUserInteraction选项,但仍然没有成功。我在这个问题上遇到了困难,所以非常感谢您的帮助 Class GameController: NSObject { var gameView: UIView! var nextB

我在NSObject类的代码中创建了一个UIbutton,它控制UIViewController类中的游戏。在游戏的大部分时间里,这个按钮都可以正常工作,但在某一点上,我希望这个按钮消失。一旦fadein/out开始设置动画,按钮就不再是交互式的。我已经设置了.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
为了测试这一点,我相信当alpha为零时不会触发按钮事件。当涉及到动画时,实际对象的alpha将在动画开始之前设置为零,您所看到的就像是视图动画时的渲染交互式屏幕截图

如果是这种情况,则需要将alpha设置为0.0100000003或覆盖按钮,使其在alpha 0处交互

AllowUserAction现在不推荐使用AllowUserAction。。。。算计

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

@Knight0fDragon回答得很好,但将alpha设置为0.0..1不会使按钮再次交互。你还有什么建议吗?我不知道如何改写这个命令UIBUtton@theAlse,我找到的最小允许alpha为0。0100000003@Knight0fDragon那么,将alpha设置为0.01将使按钮再次交互?@theAlse,不,这比我给出的数字小you@Knight0fDragon我没有得到神奇的数字0.0100000003,但会尝试一下