Paint.HomeScreen.scrollView_Scrolled C# (CSharp) Method

scrollView_Scrolled() private method

private scrollView_Scrolled ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void scrollView_Scrolled(object sender, EventArgs e)
        {
            /* Based on http://www.accella.net/objective-c-using-a-uiscrollview-for-infinite-page-loops/ */
            // Code is improved to ensure no problems with delayed loading if the user scrolls too fast.
            // Thus we are using the Scrolled method rather than the DecelerationEnded method.

            if (this.fileListLength == 0)
            {
                return;
            }

            float xOffset = scrollView.ContentOffset.X;

            if (xOffset > this.maxForwardScroll)
            {
                // We are moving forward so move the images to the previous UIImageView
                this.imageViewList[0].Image = this.imageViewList[1].Image;
                this.imageViewList[1].Image = this.imageViewList[2].Image;

                // Add one to the currentIndex or reset to 0 if we have reached the end.
                this.currentFileIndex = (this.currentFileIndex >= this.fileListLength - 1) ? 0 : this.currentFileIndex + 1;

                // Load content on the last page. This is either from the next item in the array
                // or the first if we have reached the end.
                int nextIndex = (this.currentFileIndex >= this.fileListLength - 1) ? 0 : this.currentFileIndex + 1;
                this.LoadImageWithIndex(2, nextIndex);

                // reset the scroll position so the user does not realise we've moved the images around
                this.scrollView.ContentOffset = new PointF(xOffset - scrollView.Frame.Width, 0f);
            }
            else if (xOffset < this.minBackwardScroll)
            {
                // We are moving backwards so move the images to the next UIImageView
                this.imageViewList[2].Image = this.imageViewList[1].Image;
                this.imageViewList[1].Image = this.imageViewList[0].Image;

                // Subtract one from the currentIndex or go to the end if we have reached the beginning.
                this.currentFileIndex = (this.currentFileIndex == 0) ? this.fileListLength - 1 : this.currentFileIndex - 1;

                // Load content on the first page. This is either from the prev item in the array
                // or the last if we have reached the beginning.
                int prevIndex = (this.currentFileIndex == 0) ? this.fileListLength - 1 : this.currentFileIndex - 1;
                this.LoadImageWithIndex(0, prevIndex);

                // reset the scroll position so the user does not realise we've moved the images around
                this.scrollView.ContentOffset = new PointF(xOffset + scrollView.Frame.Width, 0f);
            }
        }