由于某些原因,手势识别器不工作,它不能使背景再次正常。我如何修复它,使选择器(self.dissmissMenu)工作?
在视图控制器中:
let menu = Menu()
@IBAction func menuButton(sender: AnyObject) {
menu.runMenu()
}
在菜单中:
import UIKit
class Menu: NSObject {
let dimming = UIView()
public func runMenu(){
if let window = UIApplication.sharedApplication().keyWindow{
dimming.frame = window.frame
dimming.backgroundColor = UIColor(white: 0, alpha: 0.5)
dimming.addGestureRecognizer(UITapGestureRecognizer(target: self, action: Selector(self.dissmissMenu())))
window.addSubview(dimming)
UIView.animateWithDuration(0.5, animations: {
self.dimming.alpha = 1
})
}
}
public func dissmissMenu(){
UIView.animateWithDuration(0.5, animations: {
self.dimming.alpha = 0
})
}
}
1条答案
按热度按时间pokxtpni1#
尝试将对
addGestureRecognizer
的调用重写为如下所示: