public SwipeUpScrollViewDelegate(SlidingContentViewController swipeUpScrollViewController, UIScrollView scrollView,
                                         HitTestView hitTestView)
        {
            _slidingContentScrollViewController = swipeUpScrollViewController;
            _scrollView = scrollView;
            _scrollView.ShowsVerticalScrollIndicator   = false;
            _scrollView.ShowsHorizontalScrollIndicator = false;
            _scrollView.ClipsToBounds          = false;
            _scrollView.AlwaysBounceVertical   = true;
            _scrollView.DirectionalLockEnabled = true;

            _hitTestView = hitTestView;

            _scrollView.Scrolled          += (sender, e) => Scrolled();
            _scrollView.DecelerationEnded += (sender, e) => DecelerationEnded();

            var tapGestureRecogniser = new UITapGestureRecognizer();

            tapGestureRecogniser.AddTarget(ScrollViewTapped);
            _scrollView.AddGestureRecognizer(tapGestureRecogniser);
        }
Example #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            AutomaticallyAdjustsScrollViewInsets = false;

            EdgesForExtendedLayout = UIRectEdge.None;

            SwipeUpScrollView = new UIScrollView();
            SwipeUpScrollView.TranslatesAutoresizingMaskIntoConstraints = false;
            AutomaticallyAdjustsScrollViewInsets = false;

            NSLayoutConstraint bottomConstraint;

            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                bottomConstraint = NSLayoutConstraint.Create(SwipeUpScrollView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View.SafeAreaLayoutGuide, NSLayoutAttribute.Bottom, 1, 0);
            }
            else
            {
                bottomConstraint = NSLayoutConstraint.Create(SwipeUpScrollView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0);
            }

            var constraints = new NSLayoutConstraint[]
            {
                NSLayoutConstraint.Create(SwipeUpScrollView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 0),
                NSLayoutConstraint.Create(SwipeUpScrollView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1, 0),
                NSLayoutConstraint.Create(SwipeUpScrollView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1, 0),
                bottomConstraint
            };

            View.AddSubview(SwipeUpScrollView);

            View.AddConstraints(constraints);

            _hitTestView = new HitTestView();
            _hitTestView.TranslatesAutoresizingMaskIntoConstraints = false;

            _hitTestBottomLayoutConstraint = NSLayoutConstraint.Create(_hitTestView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0);

            var hitTestViewConstraints = new NSLayoutConstraint[]
            {
                _hitTestBottomLayoutConstraint,
                NSLayoutConstraint.Create(_hitTestView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1, 0),
                NSLayoutConstraint.Create(_hitTestView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1, 0),
                NSLayoutConstraint.Create(_hitTestView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, 0)
            };

            View.AddSubview(_hitTestView);

            View.AddConstraints(hitTestViewConstraints);

            SwipeUpScrollViewDelegate = new SwipeUpScrollViewDelegate(this, SwipeUpScrollView, _hitTestView);

            _hitTestView.SwipeUpScrollView = SwipeUpScrollView;

            //Initialise fields in delegate now that the view has loaded
            UpdateTapToRaise();
            UpdateSwipeUpView();
            UpdateSwipeUpScrollViewHeight();
            UpdateScaling();
        }