Ejemplo n.º 1
0
        public void SetupController(RectangleF rect, UIView header, UIView rowHeader, UIView content, bool enableZoom)
        {
            _content = content;
            _headerContent = header;
            _rowHeaderContent = rowHeader;

            _headerDelegate = new MyScrollViewDelegate();
            _headerDelegate.theView = _headerContent;
            _rHeaderDelegate = new MyScrollViewDelegate();
            if (rowHeader != null)
                _rHeaderDelegate.theView = _rowHeaderContent;
            _mainContentDelegate = new MyScrollViewDelegate();
            _mainContentDelegate.theView = _content;

            float minZoom = .4f;
            float maxZoom = 1.3f;

            SizeF hSize = header.Frame.Size;
            SizeF cSize = content.Frame.Size;
            SizeF rSize;
            if (rowHeader != null)
                rSize = rowHeader.Frame.Size;
            else
                rSize = new SizeF(0, 0);
            //Set the content width to match the top header width
            if (hSize.Width > cSize.Width)
                cSize.Width = hSize.Width;
            else
                hSize.Width = cSize.Width;
            // Set the content height to match the
            if (rSize.Height > cSize.Height)
                cSize.Height = rSize.Height;
            else
                rSize.Height = cSize.Height;
            // Create the viewable size based off of the current frame;
            var hRect = new RectangleF(rSize.Width, 0, rect.Width - rSize.Width, hSize.Height);
            var cRect = new RectangleF(rSize.Width, hSize.Height, rect.Width - rSize.Width, rect.Height - hSize.Height);
            var rRect = new RectangleF(0, hSize.Height, rSize.Width, rect.Height - hSize.Height);
            _headerFrame = hRect;
            _rHeaderFrame = rRect;

            _header = new UIScrollView(hRect);
            _header.ContentSize = hSize;
            _header.Bounces = false;
            // Hide scroll bars on the headers
            _header.ShowsVerticalScrollIndicator = false;
            _header.ShowsHorizontalScrollIndicator = false;
            if (enableZoom)
            {
                // Sets the zoom level
                _header.MaximumZoomScale = maxZoom;
                _header.MinimumZoomScale = minZoom;
                // create a delegate to return the zoom image.
                //_header.ViewForZoomingInScrollView += delegate {return _headerContent;};
            }

            _headerDelegate.Scrolling += delegate
                                             {
                                                 if (!_mainContent.Zooming && !isZooming)
                                                 {
                                                     scrollContent();
                                                     scrollHeader();
                                                 }
                                             };
            _header.Delegate = _headerDelegate;
            _header.AddSubview(header);

            _mainContent = new UIScrollView(cRect);
            _mainContent.ContentSize = cSize;
            _mainContent.AddSubview(content);
            _mainContent.Bounces = false;
            ContentSize = cRect.Size;
            if (enableZoom)
            {
                _mainContent.MaximumZoomScale = maxZoom;
                _mainContent.MinimumZoomScale = minZoom;
                _mainContent.BouncesZoom = false;
                // create a delegate to return the zoom image.
                //_mainContent.ViewForZoomingInScrollView += delegate {return _content;};

                _mainContentDelegate.ZoomStarted += delegate
                                                        {
                                                            //Tell the class you are zooming
                                                            isZooming = true;
                                                            ZoomHeader();
                                                        };
                _mainContentDelegate.ZoomEnded += delegate
                                                      {
                                                          ZoomHeader();
                                                          isZooming = false;
                                                          // Rescroll the content to make sure it lines up with the header
                                                            if(Zoomed != null)
                                                                Zoomed();
                                                          //scrollContent();
                                                      };
            }

            _mainContentDelegate.Scrolling += delegate
                                                  {
                                                      scrollHeader();
                                                      ZoomHeader();
                                                      //Rescroll the content to make sure it lines up with the header
                                                      if (!_mainContent.Zooming && !isZooming)
                                                          scrollContent();
                                                        this.ContentOffset =  _mainContent.ContentOffset;
                                                        if(this.Scrolled != null)
                                                            Scrolled(this,null);
                                                  };
            _mainContent.Delegate = _mainContentDelegate;

            _rowHeader = new UIScrollView(rRect);
            _rowHeader.ContentSize = rSize;
            _rowHeader.Bounces = false;
            if (enableZoom)
            {
                _rowHeader.MaximumZoomScale = maxZoom;
                _rowHeader.MinimumZoomScale = minZoom;
                //if (rowHeader != null)
                //_rowHeader.ViewForZoomingInScrollView += delegate {return _rowHeaderContent;};
            }
            // Hide scroll bars on the headers
            _rowHeader.ShowsVerticalScrollIndicator = false;
            _rowHeader.ShowsHorizontalScrollIndicator = false;
            if (rowHeader != null)
                _rowHeader.AddSubview(rowHeader);

            _rHeaderDelegate.Scrolling += delegate
                                              {
                                                  if (!_mainContent.Zooming && !isZooming)
                                                      scrollContent();
                                              };
            _rowHeader.Delegate = _rHeaderDelegate;

            AddSubview(_header);
            AddSubview(_rowHeader);
            AddSubview(_mainContent);
        }
        public void SetupController(RectangleF rect, UIView header, UIView rowHeader, UIView content, bool enableZoom)
        {
            _content          = content;
            _headerContent    = header;
            _rowHeaderContent = rowHeader;

            _headerDelegate         = new MyScrollViewDelegate();
            _headerDelegate.theView = _headerContent;
            _rHeaderDelegate        = new MyScrollViewDelegate();
            if (rowHeader != null)
            {
                _rHeaderDelegate.theView = _rowHeaderContent;
            }
            _mainContentDelegate         = new MyScrollViewDelegate();
            _mainContentDelegate.theView = _content;

            float minZoom = .4f;
            float maxZoom = 1.3f;

            SizeF hSize = header.Frame.Size;
            SizeF cSize = content.Frame.Size;
            SizeF rSize;

            if (rowHeader != null)
            {
                rSize = rowHeader.Frame.Size;
            }
            else
            {
                rSize = new SizeF(0, 0);
            }
            //Set the content width to match the top header width
            if (hSize.Width > cSize.Width)
            {
                cSize.Width = hSize.Width;
            }
            else
            {
                hSize.Width = cSize.Width;
            }
            // Set the content height to match the
            if (rSize.Height > cSize.Height)
            {
                cSize.Height = rSize.Height;
            }
            else
            {
                rSize.Height = cSize.Height;
            }
            // Create the viewable size based off of the current frame;
            var hRect = new RectangleF(rSize.Width, 0, rect.Width - rSize.Width, hSize.Height);
            var cRect = new RectangleF(rSize.Width, hSize.Height, rect.Width - rSize.Width, rect.Height - hSize.Height);
            var rRect = new RectangleF(0, hSize.Height, rSize.Width, rect.Height - hSize.Height);

            _headerFrame  = hRect;
            _rHeaderFrame = rRect;

            _header             = new UIScrollView(hRect);
            _header.ContentSize = hSize;
            _header.Bounces     = false;
            // Hide scroll bars on the headers
            _header.ShowsVerticalScrollIndicator   = false;
            _header.ShowsHorizontalScrollIndicator = false;
            if (enableZoom)
            {
                // Sets the zoom level
                _header.MaximumZoomScale = maxZoom;
                _header.MinimumZoomScale = minZoom;
                // create a delegate to return the zoom image.
                //_header.ViewForZoomingInScrollView += delegate {return _headerContent;};
            }

            _headerDelegate.Scrolling += delegate
            {
                if (!_mainContent.Zooming && !isZooming)
                {
                    scrollContent();
                    scrollHeader();
                }
            };
            _header.Delegate = _headerDelegate;
            _header.AddSubview(header);


            _mainContent             = new UIScrollView(cRect);
            _mainContent.ContentSize = cSize;
            _mainContent.AddSubview(content);
            _mainContent.Bounces = false;
            ContentSize          = cRect.Size;
            if (enableZoom)
            {
                _mainContent.MaximumZoomScale = maxZoom;
                _mainContent.MinimumZoomScale = minZoom;
                _mainContent.BouncesZoom      = false;
                // create a delegate to return the zoom image.
                //_mainContent.ViewForZoomingInScrollView += delegate {return _content;};

                _mainContentDelegate.ZoomStarted += delegate
                {
                    //Tell the class you are zooming
                    isZooming = true;
                    ZoomHeader();
                };
                _mainContentDelegate.ZoomEnded += delegate
                {
                    ZoomHeader();
                    isZooming = false;
                    // Rescroll the content to make sure it lines up with the header
                    if (Zoomed != null)
                    {
                        Zoomed();
                    }
                    //scrollContent();
                };
            }

            _mainContentDelegate.Scrolling += delegate
            {
                scrollHeader();
                ZoomHeader();
                //Rescroll the content to make sure it lines up with the header
                if (!_mainContent.Zooming && !isZooming)
                {
                    scrollContent();
                }
                this.ContentOffset = _mainContent.ContentOffset;
                if (this.Scrolled != null)
                {
                    Scrolled(this, null);
                }
            };
            _mainContent.Delegate = _mainContentDelegate;


            _rowHeader             = new UIScrollView(rRect);
            _rowHeader.ContentSize = rSize;
            _rowHeader.Bounces     = false;
            if (enableZoom)
            {
                _rowHeader.MaximumZoomScale = maxZoom;
                _rowHeader.MinimumZoomScale = minZoom;
                //if (rowHeader != null)
                //_rowHeader.ViewForZoomingInScrollView += delegate {return _rowHeaderContent;};
            }
            // Hide scroll bars on the headers
            _rowHeader.ShowsVerticalScrollIndicator   = false;
            _rowHeader.ShowsHorizontalScrollIndicator = false;
            if (rowHeader != null)
            {
                _rowHeader.AddSubview(rowHeader);
            }

            _rHeaderDelegate.Scrolling += delegate
            {
                if (!_mainContent.Zooming && !isZooming)
                {
                    scrollContent();
                }
            };
            _rowHeader.Delegate = _rHeaderDelegate;

            AddSubview(_header);
            AddSubview(_rowHeader);
            AddSubview(_mainContent);
        }