Exemplo n.º 1
0
 void CleanUpPageControl()
 {
     if (pageControl != null)
     {
         pageControl.RemoveFromSuperview();
         pageControl.Dispose();
         pageControl = null;
     }
 }
Exemplo n.º 2
0
        private void setScroll(float w, float h)
        {
            heightscroll = h - 45; //this.View.Bounds.Height;
            widthscroll  = w;      //this.View.Bounds.Width;;

            if (sramdom != null)
            {
                foreach (UIView v in sramdom)
                {
                    v.RemoveFromSuperview();
                    v.Dispose();
                }

                sramdom.RemoveFromSuperview();
                sramdom.Dispose();
                sramdom = null;
            }

            if (pageControl != null)
            {
                pageControl.RemoveFromSuperview();
                pageControl.Dispose();
                pageControl = null;
            }

            sramdom = new UIScrollView(new RectangleF(0, 0, widthscroll, heightscroll));

            try {
                if (dataPos.galerias.Count <= 0)
                {
                    UIImageView imgViewMainImage = new UIImageView(UIImage.FromFile("images/NOIMG.png"));
                    imgViewMainImage.Frame                  = this.View.Frame;
                    imgViewMainImage.ContentMode            = UIViewContentMode.ScaleAspectFit;
                    imgViewMainImage.UserInteractionEnabled = true;
                    this.View.AddSubview(imgViewMainImage);
                    return;
                }

                // UIImage image;
                var sw = this.View.Bounds.Width;

                //if (w == 1024)
                //	w = 850;

                pageControl = new UIPageControl(new RectangleF(0, heightscroll - 100, w, 20));
                pageControl.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
                // vistaImagenes = new UIView (new RectangleF (0, 0, 320 , 367));
                //MyScrollView = new UIScrollView (new RectangleF (0, 0,320 , 367));
                //pageControl.BackgroundColor = UIColor.Gray;//  .Clear ;
                RectangleF scrollFrame = sramdom.Frame;
                //MyScrollView.BackgroundColor =UIColor.Green ;
                //if (gal.Count <= 5)
                scrollFrame.Width = scrollFrame.Width * dataPos.galerias.Count;
                //else
                //  scrollFrame.Width = scrollFrame.Width * 5;

                sramdom.Scrolled += delegate(object sender, EventArgs e) {
                    try {
                        double page = Math.Floor((sramdom.ContentOffset.X - sramdom.Frame.Width / 2) / sramdom.Frame.Width) + 1;
                        pageControl.CurrentPage = (int)page;
                        positionImg             = (int)page;
                    } catch {
                    }
                };

                pageControl.ValueChanged += delegate(object sender, EventArgs e) {
                    var    pc         = (UIPageControl)sender;
                    double fromPage   = Math.Floor((sramdom.ContentOffset.X - sramdom.Frame.Width / 2) / sramdom.Frame.Width) + 1;
                    var    toPage     = pc.CurrentPage;
                    var    pageOffset = sramdom.Frame.Width * toPage;
                    if (fromPage > toPage)
                    {
                        pageOffset = sramdom.ContentOffset.X - sramdom.Frame.Width;
                    }
                    PointF p = new PointF(pageOffset, 0);
                    sramdom.SetContentOffset(p, true);
                    //btnaddItinerary.SetTitle ("+ Bookmark", UIControlState.Normal);
                };

                pageControl.Hidden = false;


                pageControl.Pages = dataPos.galerias.Count;
                //  else
                //      pageControl.Pages = 5;//maximo 5 imagenes



                sramdom.BackgroundColor = base.headerColor;


                sramdom.PagingEnabled = true;
                sramdom.ContentSize   = scrollFrame.Size;
                sramdom.ShowsHorizontalScrollIndicator = false;
                //sramdom.AutoresizingMask = UIViewAutoresizing.All;
                RectangleF frame = sramdom.Frame;
                frame.X = 0;
                int i = 0;
                foreach (galeriaImagenes g in dataPos.galerias)


                {
                    System.Drawing.RectangleF Fr = new System.Drawing.RectangleF(frame.Width * i, 0, widthscroll, heightscroll);



                    UIImageView imgViewMainImage = new UIImageView();                            //(UIImage.FromFile("images/"+namebigPicture));
                    imgViewMainImage.Frame                  = Fr;
                    imgViewMainImage.ContentMode            = UIViewContentMode.ScaleAspectFill; // .ScaleToFill;
                    imgViewMainImage.UserInteractionEnabled = true;
                    imgViewMainImage.Tag = i;
                    sramdom.InsertSubview(imgViewMainImage, 0);


                    object[] on = new object[2];
                    on [0] = imgViewMainImage;
                    on [1] = g;
                    System.Threading.ThreadPool.QueueUserWorkItem(RequestImage, on);



                    i++;
                }
                this.View.AddSubview(sramdom);
                this.View.AddSubview(pageControl);
            } catch {
            }
        }