This commit is contained in:
Sebastien Pouliot 2011-08-26 16:52:03 -04:00
Родитель d7e589d0f2
Коммит eb30d9f600
11 изменённых файлов: 2885 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace ZoomingPdfViewer
{
/// <summary>
/// The UIApplicationDelegate for the application. This class is responsible for launching the
/// User Interface of the application, as well as listening (and optionally responding) to
/// application events from iOS.
/// </summary>
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
ZoomingPdfViewerViewController viewController;
/// <summary>
/// This method is invoked when the application has loaded and is ready to run. In this
/// method you should instantiate the window, load the UI into it and then make the window
/// visible.
/// </summary>
/// <remarks>
/// You have limited time to return from this method, or iOS will terminate your application.
/// </remarks>
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
viewController = new ZoomingPdfViewerViewController ("ZoomingPdfViewerViewController", null);
window.RootViewController = viewController;
window.MakeKeyAndVisible ();
return true;
}
}
}

Просмотреть файл

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>ZoomingPdfViewer</string>
<key>CFBundleIconFiles</key>
<array>
<string>57_icon.png</string>
<string>29_icon.png</string>
</array>
<key>CFBundleIdentifier</key>
<string>com.xamarin.sample.zoomingpdfviewer</string>
<key>UIDeviceFamily</key>
<array>
<string>1</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

21
ZoomingPdfViewer/Main.cs Normal file
Просмотреть файл

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace ZoomingPdfViewer
{
public class Application
{
/// <summary>
/// This is the main entry point of the application.
/// </summary>
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
}

Просмотреть файл

@ -0,0 +1,141 @@
using System;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
using System.Drawing;
namespace ZoomingPdfViewer {
public class PdfScrollView : UIScrollView {
// main, visible, pdf view
TiledPdfView pdfView;
// temporary, while zooming, view
TiledPdfView oldPdfView;
// low resolution bitmap using until 'pdfView' is ready
UIImageView backgroundImageView;
// global reference to the PDF document/page
CGPDFDocument pdf;
CGPDFPage page;
float scale;
public PdfScrollView (RectangleF 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'
RectangleF pageRect = page.GetBoxRect (CGPDFBox.Media);
scale = Frame.Width / pageRect.Width;
pageRect.Size = new SizeF (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, 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;
RectangleF rect = pdfView.Page.GetBoxRect (CGPDFBox.Media);
rect.Size = new SizeF (rect.Width * scale, rect.Height * scale);
pdfView = new TiledPdfView (rect, scale);
pdfView.Page = page;
AddSubview (pdfView);
};
}
public override void LayoutSubviews ()
{
base.LayoutSubviews ();
// if the page becomes smaller than the view's bounds then we
// center it in the screen
SizeF boundsSize = Bounds.Size;
RectangleF frameToCenter = pdfView.Frame;
if (frameToCenter.Width < boundsSize.Width)
frameToCenter.X = (boundsSize.Width - frameToCenter.Width) / 2;
else
frameToCenter.X = 0;
if (frameToCenter.Height < boundsSize.Height)
frameToCenter.Y = (boundsSize.Height - frameToCenter.Height) / 2;
else
frameToCenter.Y = 0;
// adjust the pdf and the bitmap views to the new, centered, frame
pdfView.Frame = frameToCenter;
backgroundImageView.Frame = frameToCenter;
// this is important wrt high resolution screen to ensure
// CATiledLayer will ask proper tile sizes
pdfView.ContentScaleFactor = 1.0f;
}
}
}

9
ZoomingPdfViewer/README Normal file
Просмотреть файл

@ -0,0 +1,9 @@
This is a port of Apple's ZoomingPDFViewer (original written in ObjectiveC) available from:
http://developer.apple.com/library/ios/#samplecode/ZoomingPDFViewer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010281
The Tamarin.pdf file was generated (Download as PDF) from:
http://en.wikipedia.org/wiki/Tamarin
Text is available under the Creative Commons Attribution-ShareAlike License [1]; additional terms may apply. See Terms of use [2] for details.
[1] http://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License
[2] http://wikimediafoundation.org/wiki/Terms_of_use

2282
ZoomingPdfViewer/Tamarin.pdf Normal file

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -0,0 +1,71 @@
using System;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.UIKit;
using System.Drawing;
namespace ZoomingPdfViewer {
public class TiledPdfView : UIView {
public TiledPdfView (RectangleF frame, float scale)
: base (frame)
{
CATiledLayer tiledLayer = Layer as CATiledLayer;
tiledLayer.LevelsOfDetail = 4;
tiledLayer.LevelsOfDetailBias = 4;
tiledLayer.TileSize = new SizeF (512, 512);
// here we still need to implement the delegate
tiledLayer.Delegate = new TiledLayerDelegate (this);
Scale = scale;
}
public CGPDFPage Page { get; set; }
public float Scale { get; set; }
public override void Draw (RectangleF rect)
{
// empty (on purpose so the delegate will draw)
}
[Export ("layerClass")]
public static Class LayerClass ()
{
// instruct that we want a CATileLayer (not the default CALayer) for the Layer property
return new Class (typeof (CATiledLayer));
}
}
class TiledLayerDelegate : CALayerDelegate {
TiledPdfView view;
public TiledLayerDelegate (TiledPdfView view)
{
this.view = view;
}
public override void DrawLayer (CALayer layer, CGContext context)
{
// keep a copy since (a) it's a _virtual_ property and (b) it could change between filling and flipping
RectangleF bounds = view.Bounds;
// fill with white background
context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
context.FillRect (bounds);
context.SaveState ();
// flip page so we render it as it's meant to be read
context.TranslateCTM (0.0f, bounds.Height);
context.ScaleCTM (1.0f, -1.0f);
// scale page at the view-zoom level
context.ScaleCTM (view.Scale, view.Scale);
context.DrawPDFPage (view.Page);
context.RestoreState ();
}
}
}

Просмотреть файл

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C23B2EC8-93C5-4959-BE9A-80B0228D9CE5}</ProjectGuid>
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>ZoomingPdfViewer</RootNamespace>
<AssemblyName>ZoomingPdfViewer</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
<MtouchDebug>true</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchDebug>true</MtouchDebug>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchI18n />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup>
<ItemGroup>
<Reference Include="monotouch" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
<None Include="README" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="ZoomingPdfViewerViewController.cs" />
<Compile Include="ZoomingPdfViewerViewController.designer.cs">
<DependentUpon>ZoomingPdfViewerViewController.cs</DependentUpon>
</Compile>
<Compile Include="TiledPdfView.cs" />
<Compile Include="PdfScrollView.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="ZoomingPdfViewerViewController.xib" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Content Include="Tamarin.pdf" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,45 @@
using MonoTouch.UIKit;
using System.Drawing;
using System;
using MonoTouch.Foundation;
namespace ZoomingPdfViewer
{
public partial class ZoomingPdfViewerViewController : UIViewController
{
public ZoomingPdfViewerViewController (string nibName, NSBundle bundle) : base (nibName, bundle)
{
PdfScrollView view = new PdfScrollView (View.Bounds);
View.AddSubview (view);
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
//any additional setup after loading the view, typically from a nib.
}
public override void ViewDidUnload ()
{
base.ViewDidUnload ();
// Release any retained subviews of the main view.
// e.g. myOutlet = null;
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
}
}
}

14
ZoomingPdfViewer/ZoomingPdfViewerViewController.designer.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,14 @@
//
// This file has been generated automatically by MonoDevelop to store outlets and
// actions made in the Xcode designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using MonoTouch.Foundation;
namespace ZoomingPdfViewer
{
[Register ("ZoomingPdfViewerViewController")]
partial class ZoomingPdfViewerViewController
{
}
}

Просмотреть файл

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">800</int>
<string key="IBDocument.SystemVersion">10C540</string>
<string key="IBDocument.InterfaceBuilderVersion">759</string>
<string key="IBDocument.AppKitVersion">1038.25</string>
<string key="IBDocument.HIToolboxVersion">458.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">77</string>
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="6" />
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys" id="0">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBProxyObject" id="372490531">
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBProxyObject" id="843779117">
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="774585933">
<reference key="NSNextResponder" />
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{320, 460}</string>
<reference key="NSSuperview" />
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MC43NQA</bytes>
<object class="NSColorSpace" key="NSCustomColorSpace">
<int key="NSID">2</int>
</object>
</object>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics" />
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">view</string>
<reference key="source" ref="372490531" />
<reference key="destination" ref="774585933" />
</object>
<int key="connectionID">7</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBObjectRecord">
<int key="objectID">0</int>
<reference key="object" ref="0" />
<reference key="children" ref="1000" />
<nil key="parent" />
</object>
<object class="IBObjectRecord">
<int key="objectID">-1</int>
<reference key="object" ref="372490531" />
<reference key="parent" ref="0" />
<string key="objectName">File's Owner</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">-2</int>
<reference key="object" ref="843779117" />
<reference key="parent" ref="0" />
</object>
<object class="IBObjectRecord">
<int key="objectID">6</int>
<reference key="object" ref="774585933" />
<reference key="parent" ref="0" />
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>-1.CustomClassName</string>
<string>-2.CustomClassName</string>
<string>6.IBEditorWindowLastContentRect</string>
<string>6.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>ZoomingPdfViewerViewController</string>
<string>UIResponder</string>
<string>{{239, 654}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference key="dict.sortedKeys" ref="0" />
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<nil key="activeLocalization" />
<object class="NSMutableDictionary" key="localizations">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference key="dict.sortedKeys" ref="0" />
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<nil key="sourceID" />
<int key="maxID">7</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">ZoomingPdfViewerViewController</string>
<string key="superclassName">UIViewController</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">ZoomingPdfViewerViewController.h</string>
</object>
</object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
<integer value="3100" key="NS.object.0" />
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<string key="IBDocument.LastKnownRelativeProjectPath">SingleViewIPhone.xcodeproj</string>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">77</string>
<nil key="IBCocoaTouchSimulationTargetRuntimeIdentifier" />
</data>
</archive>