Exemplo n.º 1
0
        public override void SendEvent(UIEvent evt)
        {
            if (evt.Type == UIEventType.Touches)
            {
                if (active)
                {
                    NSSet allTouches = evt.AllTouches;

                    foreach (UITouch touch in allTouches)
                    {
                        switch (touch.Phase)
                        {
                        case UITouchPhase.Began:
                        case UITouchPhase.Moved:
                        case UITouchPhase.Stationary:

                            MBFingerTipView touchView = OverlayWindow().ViewWithTag(touch.GetHashCode()) as MBFingerTipView;

                            if (touch.Phase != UITouchPhase.Stationary && touchView != null && touchView.isFadingOut)
                            {
                                touchView.RemoveFromSuperview();
                                touchView = null;
                            }

                            if (touchView == null && touch.Phase != UITouchPhase.Stationary)
                            {
                                touchView = new MBFingerTipView(TouchImage());
                                OverlayWindow().AddSubview(touchView);
                            }

                            if (!touchView.isFadingOut)
                            {
                                touchView.Alpha     = touchAlpha;
                                touchView.Center    = touch.LocationInView(OverlayWindow());
                                touchView.Tag       = touch.GetHashCode();
                                touchView.timestamp = TimeSpan.FromSeconds(touch.Timestamp);
                                touchView.shouldAutomaticallyRemoveAfterTimeout = shouldAutomaticallyRemoveFingerTipForTouch(touch);
                            }

                            break;


                        case UITouchPhase.Ended:
                        case UITouchPhase.Cancelled:
                            removeFingerTipWithHash(touch.GetHashCode(), true);

                            break;
                        }
                    }
                }

                scheduleFingerTipRemoval();
            }

            base.SendEvent(evt);
        }
Exemplo n.º 2
0
        void removeFingerTipWithHash(nint hash, bool animated)
        {
            MBFingerTipView touchView = OverlayWindow().ViewWithTag(hash) as MBFingerTipView;

            if (!(touchView is MBFingerTipView))
            {
                return;
            }

            if (touchView.isFadingOut)
            {
                return;
            }

            bool animationsWereEnabled = UIView.AnimationsEnabled;

            if (animated)
            {
                UIView.AnimationsEnabled = true;
                UIView.BeginAnimations(null, IntPtr.Zero);
                UIView.SetAnimationDuration(fadeDuration);
            }

            touchView.Frame = new CGRect(touchView.Center.X - touchView.Frame.Size.Width,
                                         touchView.Center.Y - touchView.Frame.Size.Height,
                                         touchView.Frame.Size.Width * 2,
                                         touchView.Frame.Size.Height * 2);

            touchView.Alpha = 0;

            if (animated)
            {
                UIView.CommitAnimations();
                UIView.AnimationsEnabled = animationsWereEnabled;
            }

            touchView.isFadingOut = true;


            var aTimer = new Timer(fadeDuration * 1000);

            aTimer.AutoReset = false;
            aTimer.Elapsed  += ((sender, e) => {
                InvokeOnMainThread(() => {
                    touchView.RemoveFromSuperview();
                });
            });
            aTimer.Enabled = true;
        }
        public override void SendEvent(UIEvent evt)
        {
            if (evt.Type == UIEventType.Touches) {
                if (active) {
                    NSSet allTouches = evt.AllTouches;

                    foreach (UITouch touch in allTouches) {

                        switch (touch.Phase) {
                        case UITouchPhase.Began:
                        case UITouchPhase.Moved:
                        case UITouchPhase.Stationary:

                            MBFingerTipView touchView = OverlayWindow ().ViewWithTag (touch.GetHashCode ()) as MBFingerTipView;

                            if (touch.Phase != UITouchPhase.Stationary && touchView != null && touchView.isFadingOut) {
                                touchView.RemoveFromSuperview ();
                                touchView = null;
                            }

                            if (touchView == null && touch.Phase != UITouchPhase.Stationary) {
                                touchView = new MBFingerTipView (TouchImage ());
                                OverlayWindow ().AddSubview (touchView);
                            }

                            if (!touchView.isFadingOut) {
                                touchView.Alpha = touchAlpha;
                                touchView.Center = touch.LocationInView (OverlayWindow ());
                                touchView.Tag = touch.GetHashCode ();
                                touchView.timestamp = TimeSpan.FromSeconds (touch.Timestamp);
                                touchView.shouldAutomaticallyRemoveAfterTimeout = shouldAutomaticallyRemoveFingerTipForTouch (touch);

                            }

                            break;

                        case UITouchPhase.Ended:
                        case UITouchPhase.Cancelled:
                            removeFingerTipWithHash (touch.GetHashCode (), true);

                            break;

                        }
                    }

                }

                scheduleFingerTipRemoval ();

            }

            base.SendEvent (evt);
        }