当前位置:  开发笔记 > 编程语言 > 正文

动画按钮允许用户交互不起作用

如何解决《动画按钮允许用户交互不起作用》经验,为你挑选了1个好方法。

我有一个在NSObject类中的代码中创建的UI按钮,它控制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

}



1> Knight0fDrag..:

拿出 self.nextButton.alpha = 0去测试一下,我相信当alpha为零时按钮事件不会触发.当涉及到动画时,实际对象的alpha将在动画开始之前设置为零,而您所看到的就像是动画的渲染交互式屏幕截图

如果是这种情况,那么您需要将alpha设置为0.0100000003或覆盖按钮以在alpha 0处进行交互

推荐阅读
ifx0448363
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有