Пример #1
0
        public new void ZoomingStarted(UIScrollView scrollView, UIView view)
        {
            // Remove back tiled view.
            oldPdfView.RemoveFromSuperview();
            oldPdfView.Dispose();

            // Set the current TiledPDFView to be the old view.
            oldPdfView = TiledPdfView;
        }
Пример #2
0
        void ReplaceTiledPDFView(CGRect rect)
        {
            // Create a new tiled PDF View at the new scale
            var tiledPDFView = new TiledPdfView(Frame, PdfScale);

            tiledPDFView.Page = page;

            // Add the new TiledPDFView to the PDFScrollView.
            AddSubview(tiledPDFView);
            TiledPDFView = tiledPDFView;
        }
Пример #3
0
        private void ReplaceTiledPdfViewWithFrame(CGRect frame)
        {
            // Create a new tiled PDF View at the new scale
            var tiledPDFView = new TiledPdfView(frame, PdfScale)
            {
                PdfPage = page
            };

            // Add the new TiledPDFView to the PDFScrollView.
            AddSubview(tiledPDFView);
            TiledPdfView = tiledPDFView;
        }
Пример #4
0
        private void Initialize()
        {
            DecelerationRate = UIScrollView.DecelerationRateFast;
            Delegate         = this;

            Layer.BorderColor = UIColor.LightGray.CGColor;
            Layer.BorderWidth = 5f;

            MaximumZoomScale = 5f;
            MinimumZoomScale = 0.25f;

            oldPdfView = new TiledPdfView(pageRect, PdfScale);
        }
Пример #5
0
		void ReplaceTiledPDFView (CGRect rect)
		{
			// Create a new tiled PDF View at the new scale
			var tiledPDFView = new TiledPdfView (Frame, PdfScale);
			tiledPDFView.Page = page;

			// Add the new TiledPDFView to the PDFScrollView.
			AddSubview (tiledPDFView);
			TiledPDFView = tiledPDFView;
		}
Пример #6
0
		public new void ZoomingStarted (UIScrollView scrollView, UIView view)
		{
			// Remove back tiled view.
			oldPdfView?.RemoveFromSuperview ();
			oldPdfView = TiledPDFView;
		}
Пример #7
0
 public TiledLayerDelegate(TiledPdfView view)
 {
     this.view = view;
     bounds = view.Bounds;
 }
Пример #8
0
        public PdfScrollView(CGRect frame)
            : base(frame)
        {
            ShowsVerticalScrollIndicator   = false;
            ShowsHorizontalScrollIndicator = false;
            BouncesZoom      = true;
            DecelerationRate = UIScrollView.DecelerationRateFast;
            BackgroundColor  = UIColor.White;
            MaximumZoomScale = 5.0f;
            MinimumZoomScale = 0.25f;

            // open the PDF file (default directory is the bundle path)
            pdf = CGPDFDocument.FromFile("Tamarin.pdf");
            // select the first page (the only one we'll use)
            page = pdf.GetPage(1);

            // make the initial view 'fit to width'
            CGRect pageRect = page.GetBoxRect(CGPDFBox.Media);

            scale         = Frame.Width / pageRect.Width;
            pageRect.Size = new CGSize(pageRect.Width * scale, pageRect.Height * scale);

            // create bitmap version of the PDF page, to be used (scaled)
            // when no other (tiled) view are visible
            UIGraphics.BeginImageContext(pageRect.Size);
            CGContext context = UIGraphics.GetCurrentContext();

            // fill with white background
            context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
            context.FillRect(pageRect);
            context.SaveState();

            // flip page so we render it as it's meant to be read
            context.TranslateCTM(0.0f, pageRect.Height);
            context.ScaleCTM(1.0f, -1.0f);

            // scale page at the view-zoom level
            context.ScaleCTM(scale, scale);
            context.DrawPDFPage(page);
            context.RestoreState();

            UIImage backgroundImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            backgroundImageView             = new UIImageView(backgroundImage);
            backgroundImageView.Frame       = pageRect;
            backgroundImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
            AddSubview(backgroundImageView);
            SendSubviewToBack(backgroundImageView);

            // Create the TiledPDFView based on the size of the PDF page and scale it to fit the view.
            pdfView      = new TiledPdfView(pageRect, (float)scale);
            pdfView.Page = page;
            AddSubview(pdfView);

            // no need to have (or set) a UIScrollViewDelegate with MonoTouch

            this.ViewForZoomingInScrollView = delegate {
                // return the view we'll be using while zooming
                return(pdfView);
            };

            // when zooming starts we remove (from view) and dispose any
            // oldPdfView and set pdfView as our 'new' oldPdfView, it will
            // stay there until a new view is available (when zooming ends)
            this.ZoomingStarted += delegate {
                if (oldPdfView != null)
                {
                    oldPdfView.RemoveFromSuperview();
                    oldPdfView.Dispose();
                }
                oldPdfView = pdfView;
                AddSubview(oldPdfView);
            };

            // when zooming ends a new TiledPdfView is created (and shown)
            // based on the updated 'scale' and 'frame'
            ZoomingEnded += delegate(object sender, ZoomingEndedEventArgs e) {
                scale *= e.AtScale;

                CGRect rect = page.GetBoxRect(CGPDFBox.Media);
                rect.Size = new CGSize(rect.Width * scale, rect.Height * scale);

                pdfView      = new TiledPdfView(rect, (float)scale);
                pdfView.Page = page;
                AddSubview(pdfView);
            };
        }
Пример #9
0
 public new void ZoomingStarted(UIScrollView scrollView, UIView view)
 {
     // Remove back tiled view.
     oldPdfView?.RemoveFromSuperview();
     oldPdfView = TiledPDFView;
 }
Пример #10
0
 public TiledLayerDelegate(TiledPdfView view)
 {
     this.view = view;
     bounds    = view.Bounds;
 }
Пример #11
0
		public PdfScrollView (CGRect frame)
			: base (frame)
		{
			ShowsVerticalScrollIndicator = false;
			ShowsHorizontalScrollIndicator = false;
			BouncesZoom = true;
			DecelerationRate = UIScrollView.DecelerationRateFast;
			BackgroundColor = UIColor.Gray;
			MaximumZoomScale = 5.0f;
			MinimumZoomScale = 0.25f;

			// open the PDF file (default directory is the bundle path)
			pdf = CGPDFDocument.FromFile ("Tamarin.pdf");
			// select the first page (the only one we'll use)
			page = pdf.GetPage (1);

			// make the initial view 'fit to width'
			CGRect pageRect = page.GetBoxRect (CGPDFBox.Media);
			scale = Frame.Width / pageRect.Width;
			pageRect.Size = new CGSize (pageRect.Width * scale, pageRect.Height * scale);

			// create bitmap version of the PDF page, to be used (scaled)
			// when no other (tiled) view are visible
			UIGraphics.BeginImageContext (pageRect.Size);
			CGContext context = UIGraphics.GetCurrentContext ();

			// fill with white background
			context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
			context.FillRect (pageRect);
			context.SaveState ();

			// flip page so we render it as it's meant to be read
			context.TranslateCTM (0.0f, pageRect.Height);
			context.ScaleCTM (1.0f, -1.0f);

			// scale page at the view-zoom level
			context.ScaleCTM (scale, scale);
			context.DrawPDFPage (page);
			context.RestoreState ();

			UIImage backgroundImage = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();

			backgroundImageView = new UIImageView (backgroundImage);
			backgroundImageView.Frame = pageRect;
			backgroundImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
			AddSubview (backgroundImageView);
			SendSubviewToBack (backgroundImageView);

			// Create the TiledPDFView based on the size of the PDF page and scale it to fit the view.
			pdfView = new TiledPdfView (pageRect, (float)scale);
			pdfView.Page = page;
			AddSubview (pdfView);

			// no need to have (or set) a UIScrollViewDelegate with MonoTouch

			this.ViewForZoomingInScrollView = delegate {
				// return the view we'll be using while zooming
				return pdfView;
			};

			// when zooming starts we remove (from view) and dispose any
			// oldPdfView and set pdfView as our 'new' oldPdfView, it will
			// stay there until a new view is available (when zooming ends)
			this.ZoomingStarted += delegate {
				if (oldPdfView != null) {
					oldPdfView.RemoveFromSuperview ();
					oldPdfView.Dispose ();
				}
				oldPdfView = pdfView;
				AddSubview (oldPdfView);
			};

			// when zooming ends a new TiledPdfView is created (and shown)
			// based on the updated 'scale' and 'frame'
			ZoomingEnded += delegate (object sender, ZoomingEndedEventArgs e) {
				scale *= e.AtScale;

				CGRect rect = page.GetBoxRect (CGPDFBox.Media);
				rect.Size = new CGSize (rect.Width * scale, rect.Height * scale);

				pdfView = new TiledPdfView (rect, (float)scale);
				pdfView.Page = page;
				AddSubview (pdfView);
			};
		}
Пример #12
0
		public TiledLayerDelegate (TiledPdfView view)
		{
			this.view = view;
		}
 public TiledLayerDelegate(TiledPdfView view)
 {
     this.view = view;
 }