예제 #1
0
        /// <summary>
        /// Initializes all the parts and controls of the parallaxing screen.
        /// </summary>
        /// <param name="background"></param>
        void Initialize()
        {
            // Set up the parallax.
            parallaxScrollView = new UIScrollView(this.Frame);

            // Set the default scroll height for the frame.
            // This is the offset where the content goes when it's snapped to the top.
            defaultScrollOffset = this.Frame.Height - 130 - 60 - 40;

            // Set up our darkening layer.
            darkerLayer = new UIView(this.Frame);
            darkerLayer.BackgroundColor = UIColor.Black;
            darkerLayer.Alpha = 0;

            // Set up our scrolling.
            scrollView = new Views.FadingScrollView(this.Frame)
            {
                ShowsHorizontalScrollIndicator = false,
                ShowsVerticalScrollIndicator = false,
                DecelerationRate = UIScrollView.DecelerationRateNormal
            };

            // Add some events to handle the scrolling.
            scrollView.Scrolled += ScrollViewDidScroll;
            scrollView.DraggingEnded += ScrollViewDraggingEnded;
            scrollView.DecelerationEnded += ScrollViewDecelerationEnded;

            // Makes sure that a tap scrolls the view up a bit.
            var tap = new UITapGestureRecognizer();
            tap.AddTarget(() => { if (scrollView.ContentOffset.Y == 0) ScrollTo(0, defaultScrollOffset); });
            scrollView.AddGestureRecognizer(tap);

            // Setup the picture frame. We make it higher then the view is due to parallax.
            RectangleF frame = this.Frame;
            frame.Size = new SizeF(frame.Width, frame.Height + frame.Height / parallaxSpeedRatio);

            // Set up the pictures.
            backgroundPhoto = new UIImageView(frame) {
                AutoresizingMask = UIViewAutoresizing.FlexibleHeight,
                ContentMode = UIViewContentMode.ScaleAspectFill
            };

            backgroundPhotoWithImageEffects = new UIImageView(frame) {
                ContentMode = UIViewContentMode.ScaleAspectFill,
                AutoresizingMask = UIViewAutoresizing.FlexibleHeight,
                Alpha = 0
            };

            // Create the header.
            header = new ParallaxBlurHeaderView(new RectangleF(0, 0, 320, 50));
            header.OnTapped += HeaderOnTapped;

            // Add our items to the view.
            parallaxScrollView.Add(backgroundPhoto);
            parallaxScrollView.Add(backgroundPhotoWithImageEffects);

            // Do the actual cross dissolve effect.
            CrossDissolvePhotos(backgroundPhoto.Image, backgroundPhotoWithImageEffects.Image);

            // Add our elements to the view.
            this.Add(parallaxScrollView);
            this.Add(darkerLayer);
            this.Add(scrollView);
            this.Add(header);
        }
예제 #2
0
        /// <summary>
        /// Initializes all the parts and controls of the parallaxing screen.
        /// </summary>
        /// <param name="background"></param>
        void Initialize()
        {
            // Set up the parallax.
            parallaxScrollView = new UIScrollView(this.Frame);

            // Set the default scroll height for the frame.
            // This is the offset where the content goes when it's snapped to the top.
            defaultScrollOffset = this.Frame.Height - 130 - 60 - 40;

            // Set up our darkening layer.
            darkerLayer = new UIView(this.Frame);
            darkerLayer.BackgroundColor = UIColor.Black;
            darkerLayer.Alpha           = 0;

            // Set up our scrolling.
            scrollView = new Views.FadingScrollView(this.Frame)
            {
                ShowsHorizontalScrollIndicator = false,
                ShowsVerticalScrollIndicator   = false,
                DecelerationRate = UIScrollView.DecelerationRateNormal
            };

            // Add some events to handle the scrolling.
            scrollView.Scrolled          += ScrollViewDidScroll;
            scrollView.DraggingEnded     += ScrollViewDraggingEnded;
            scrollView.DecelerationEnded += ScrollViewDecelerationEnded;

            // Makes sure that a tap scrolls the view up a bit.
            var tap = new UITapGestureRecognizer();

            tap.AddTarget(() => { if (scrollView.ContentOffset.Y == 0)
                                  {
                                      ScrollTo(0, defaultScrollOffset);
                                  }
                          });
            scrollView.AddGestureRecognizer(tap);

            // Setup the picture frame. We make it higher then the view is due to parallax.
            RectangleF frame = this.Frame;

            frame.Size = new SizeF(frame.Width, frame.Height + frame.Height / parallaxSpeedRatio);

            // Set up the pictures.
            backgroundPhoto = new UIImageView(frame)
            {
                AutoresizingMask = UIViewAutoresizing.FlexibleHeight,
                ContentMode      = UIViewContentMode.ScaleAspectFill
            };

            backgroundPhotoWithImageEffects = new UIImageView(frame)
            {
                ContentMode      = UIViewContentMode.ScaleAspectFill,
                AutoresizingMask = UIViewAutoresizing.FlexibleHeight,
                Alpha            = 0
            };

            // Create the header.
            header           = new ParallaxBlurHeaderView(new RectangleF(0, 0, 320, 50));
            header.OnTapped += HeaderOnTapped;

            // Add our items to the view.
            parallaxScrollView.Add(backgroundPhoto);
            parallaxScrollView.Add(backgroundPhotoWithImageEffects);

            // Do the actual cross dissolve effect.
            CrossDissolvePhotos(backgroundPhoto.Image, backgroundPhotoWithImageEffects.Image);

            // Add our elements to the view.
            this.Add(parallaxScrollView);
            this.Add(darkerLayer);
            this.Add(scrollView);
            this.Add(header);
        }