protected override void OnDetached()
 {
     _view?.RemoveGestureRecognizer(_recognizer);
     _view = null;
     _recognizer?.Dispose();
     _recognizer = null;
 }
        protected override void OnDetached()
        {
            _toucheController.TouchBegin  -= OnTouchBegin;
            _toucheController.TouchEnd    -= OnTouchEnd;
            _toucheController.TouchCancel -= OnTouchEnd;

            _view.RemoveGestureRecognizer(_touchRecognizer);
            _touchRecognizer.Delegate?.Dispose();
            _touchRecognizer.Delegate = null;
            _touchRecognizer.Dispose();

            _touchRecognizer  = null;
            _toucheController = null;

            _layer.RemoveFromSuperview();
            _layer.Dispose();
            _layer = null;

            _clickSound?.Dispose();
            _clickSound = null;

            _view = null;

            System.Diagnostics.Debug.WriteLine($"Detached {GetType().Name} from {Element.GetType().FullName}");
        }
        protected override void OnAttached()
        {
            _view = Control ?? Container;

            _recognizer = new TouchEffectGestureRecognizer(AddTouch.GetRecognizer(Element));

            _view.AddGestureRecognizer(_recognizer);
        }
        protected override void OnDetached()
        {
            Element.ClearValue(AddTouch.RecognizerProperty);
            _view?.RemoveGestureRecognizer(_recognizer);
            _view = null;
            _recognizer?.Dispose();
            _recognizer = null;

            System.Diagnostics.Debug.WriteLine($"Detached {GetType().Name} from {Element.GetType().FullName}");
        }
        protected override void OnAttached()
        {
            _view = Control ?? Container;

            _view.UserInteractionEnabled = true;

            _layer = new UIView {
                Alpha  = 0,
                Opaque = false,
                UserInteractionEnabled = false
            };
            _view.AddSubview(_layer);

            _layer.TranslatesAutoresizingMaskIntoConstraints = false;

            _layer.TopAnchor.ConstraintEqualTo(_view.TopAnchor).Active       = true;
            _layer.LeftAnchor.ConstraintEqualTo(_view.LeftAnchor).Active     = true;
            _layer.BottomAnchor.ConstraintEqualTo(_view.BottomAnchor).Active = true;
            _layer.RightAnchor.ConstraintEqualTo(_view.RightAnchor).Active   = true;


            _view.BringSubviewToFront(_layer);

            _toucheController         = new TouchRecognizer();
            _touchRecognizer          = new TouchEffectGestureRecognizer(_toucheController);
            _touchRecognizer.Delegate = new AlwaysSimultaneouslyGestureRecognizerDelegate();

            _view.AddGestureRecognizer(_touchRecognizer);

            _toucheController.TouchBegin  += OnTouchBegin;
            _toucheController.TouchEnd    += OnTouchEnd;
            _toucheController.TouchCancel += OnTouchEnd;

            UpdateEffectColor();
            UpdateEnableSound();
        }