Я пытаюсь показать некоторый контент с пользовательским UIView
как всплывающее окно, до сих пор я сделал это хорошо, я хочу выпустить всплывающее окно, коснувшись всплывающего окна, я не могу добиться успеха, я новичок в быстром языке, пожалуйста, вы можете мне помочь с этим, все только код, скопированный из Google толькоНеполадки при нажатии и отсутствии событий, которые создаются с помощью пользовательского uiview с xib?
код для Пользовательской UIView
import UIKit
class PopUpView: UIView {
var view = UIView()
var _myTap: UITapGestureRecognizer?
// this name has to match your class file and your xib file
@IBOutlet weak var lblContent: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
override func awakeFromNib()
{
self.userInteractionEnabled = true
}
func _myHandleTap(sender: UITapGestureRecognizer) {
if sender.state == .Ended {
print("_myHandleTap(sender.state == .Ended)")
sender.view!.backgroundColor
= UIColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0);
self .hideInView()
}
}
func setup() {
// setup the view from .xib
view = loadViewFromNib()
view .userInteractionEnabled = true
self .userInteractionEnabled = true
view.backgroundColor = UIColor.clearColor()
_myTap = UITapGestureRecognizer(target: self
, action: #selector(_myHandleTap(_:)))
_myTap!.numberOfTapsRequired = 1
view.addGestureRecognizer(_myTap!)
}
func loadViewFromNib() -> UIView {
// grabs the appropriate bundle
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: "PopUpView", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}
func showInView(currentView:UIView,content:String) {
view.frame = currentView.bounds
currentView .userInteractionEnabled = true
lblContent.text = content
UIApplication.sharedApplication().keyWindow!.addSubview(view)
view.alpha = 0
UIView.animateWithDuration(0.2, delay: 0.2, options: [.CurveEaseInOut], animations: {
self.view.alpha = 1
}, completion: nil)
}
func hideInView() {
view.alpha = 0
UIView.animateWithDuration(0.2, delay: 0.2, options: [.Repeat, .CurveEaseInOut], animations: {
self.view.alpha = 0
self.view .removeFromSuperview()
}, completion: nil)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self .hideInView()
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}
к нему доступ из моего UIViewController
@IBAction func doForgotAction(sender: AnyObject) {
// warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
let custom = PopUpView()
custom .showInView(self .view, content: "welcome")
}
Ваша функция _myHandleTap называется? –
, который не звонит, я проверил с точкой останова. –