Example #1
0
        /// <summary>
        /// Adds the view into the scroll view that is auto-zoomed, best-fit, orientable and re-entrant.
        /// </summary>
        /// <param name="scrollView">Scroll view.</param>
        /// <param name="contentView">Content view.</param>
        public static void SetZoomableContentView(this UIScrollView scrollView, UIView contentView)
        {
            // Remove fixer if has one
            if (Tools.iOSTool.HasRuntimeProperty(scrollView, "ScrollViewFixer"))
            {
                scrollView.UnsetZoomableContentView();
            }

            scrollView.RemoveAndDisposeChildSubViews();
            var scrollViewFixer = new ScrollViewObserver(contentView);

            scrollView.AddObserver(
                observer: scrollViewFixer,
                keyPath: new NSString("bounds"),
                options: NSKeyValueObservingOptions.OldNew,
                context: IntPtr.Zero
                );

            if (scrollView.Frame != RectangleF.Empty)
            {
                ScrollViewObserver.ConfigureScrollView(scrollView, contentView, Guid.Empty);
            }

            Tools.iOSTool.AddRuntimeProperty(scrollView, scrollViewFixer, "ScrollViewFixer", AssociationPolicy.RETAIN_NONATOMIC);
        }
Example #2
0
        public override void SubviewAdded(UIView uiview)
        {
            base.SubviewAdded(uiview);

            var scroll = uiview as UIScrollView;

            if (scroll != null)
            {
                if (scrollView != null)
                {
                    throw new InvalidOperationException("Cannot add multiple UIScrollView sub views to PullToBounceWrapper.");
                }
                scrollView = scroll;

                scrollView.AddObserver(this, contentOffsetKeyPath, NSKeyValueObservingOptions.Initial, observerContext.Handle);
            }
        }
    public ODRefreshControl (UIScrollView scrollView, ODRefreshControlLayout layout = ODRefreshControlLayout.Vertical, UIView activity = null)
        : base (
            (layout == ODRefreshControlLayout.Vertical)
            ? new RectangleF (0, (-TotalViewHeight - scrollView.ContentInset.Top), scrollView.Bounds.Width, TotalViewHeight)
            : new RectangleF ((-TotalViewHeight - scrollView.ContentInset.Left), 0, TotalViewHeight, scrollView.Bounds.Height)
            )
    {
        ScrollView = scrollView;
        OriginalContentInset = scrollView.ContentInset;

        _vertical = (layout == ODRefreshControlLayout.Vertical);

        AutoresizingMask = (_vertical)
            ? UIViewAutoresizing.FlexibleWidth
            : UIViewAutoresizing.FlexibleHeight;
        
        ScrollView.AddSubview (this);
        ScrollView.AddObserver (this, new NSString ("contentOffset"), NSKeyValueObservingOptions.New, IntPtr.Zero);
        ScrollView.AddObserver (this, new NSString ("contentInset"), NSKeyValueObservingOptions.New, IntPtr.Zero);
        
        _activity = activity ?? new UIActivityIndicatorView (UIActivityIndicatorViewStyle.Gray);
        _activity.Center = new PointF ((float) Math.Floor (Bounds.Width / 2.0f), (float) Math.Floor (Bounds.Height / 2.0f));
        
        _activity.AutoresizingMask = (_vertical)
            ? UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin
            : UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleBottomMargin;
        
        _activity.Alpha = 1;
        
        if (_activity is UIActivityIndicatorView) {
            ((UIActivityIndicatorView) _activity).StartAnimating ();
        }
        AddSubview (_activity);
        
        _refreshing = false;
        _canRefresh = true;
        
        _ignoreInset = false;
        _ignoreOffset = false;
        _didSetInset = false;
        _hasSectionHeaders = false;

        _tintColor = UIColor.FromRGB (155, 162, 172);
        _shadowColor = UIColor.Black;
        _highlightColor = UIColor.White.ColorWithAlpha (.2f);

        _shapeLayer = new CAShapeLayer {
            FillColor = _tintColor.CGColor,
            StrokeColor = UIColor.DarkGray.ColorWithAlpha (.5f).CGColor,
            LineWidth = .5f,
            ShadowColor = _shadowColor.CGColor,
            ShadowOffset = new SizeF (0, 1),
            ShadowOpacity = .4f,
            ShadowRadius = .5f
        };
        
        Layer.AddSublayer (_shapeLayer);
        
        _arrowLayer = new CAShapeLayer {
            StrokeColor = UIColor.DarkGray.ColorWithAlpha (.5f).CGColor,
            LineWidth = .5f,
            FillColor = UIColor.White.CGColor
        };
        
        _shapeLayer.AddSublayer (_arrowLayer);

        _highlightLayer = new CAShapeLayer {
            FillColor = _highlightColor.CGColor
        };

        _shapeLayer.AddSublayer (_highlightLayer);

        if (!_vertical) {
            // Highlight layer is currently not shown in horizontal mode
            // because it has a wrong path.

            // It should instead be drawn all the way from left to right circle.
            // Feel free to work on it!

            _highlightLayer.RemoveFromSuperLayer ();
        }
    }