次ã«ãMonotouchãã©ãããã©ãŒã ãšiOSã§ã®PDFããã¥ã¡ã³ãã®è¡šç€ºã«ã€ããŠèª¬æããŸãã ãã®ãããã¯ã§ã¯ãã©ã€ãã©ãªã®ãœãŒã¹ã³ãŒãã®æãæäŸããŸãã;ãããå¿ èŠãšãã人ã¯GitHubã§ããããèŠã€ããŸãããã©ã€ãã©ãªãæ§ç¯ãããšãã«çããè€éãªåé¡ã«éäžããããšããŸãã
確ãã«ãMonotouchã䜿çšããå€ãã®iOSéçºè ã¯ãããã°ã©ã ã§PDFããã¥ã¡ã³ãã衚瀺ãããšãã課é¡ã«çŽé¢ããŠããŸããã ãã°ããåã«ãããã°ã©ã ãéçºãããšãã«ãã®ãããªåé¡ã«çŽé¢ããŸããã iOSã§PDFææžã衚瀺ããããã«æäŸãããæšæºãªãã·ã§ã³ã調ã¹ãåŸïŒä»¥äžã®æ¯èŒè¡šãåç §ïŒãã©ã€ãã©ãªãæžãããšãäžå¯æ¬ ã§ããããšã«æ°ä»ããŸããã ã©ã€ãã©ãªãäœæãããšããiOS 5ã¯ãŸã ãªãªãŒã¹ãããŠããããæ°ããPageControlã³ã³ããŒãã³ãã¯æå ã«ãªãã£ããšããã«èšãããã§ãã
- UIWebViewã¯ééããªãè¯ãããšã§ããããã¢ãããžã§ã¯ãã«ã®ã¿é©ããŠããŸãã ã³ã³ãããŒã«ã¯ããŸããŸãªããã¥ã¡ã³ã圢åŒã衚瀺ã§ããŸããã衚瀺ã®å質ã¯ããã¥ã¡ã³ãã®å
容ã«å€§ããäŸåããŸãã WordææžãExcelã¯è¯å¿ã®twinãªãã«åæãããäžéšã®PDFææžã¯ãŸã£ããéãããInnerExceptionãå ±åãããŸãã
- QLPreviewController-ååã«ãã£ãŠå€æãããšãããã¥ã¡ã³ãã®äºå衚瀺ãç®çãšãããã®ãMacOSã§äœ¿çšãããŸãã MS Officeããã¥ã¡ã³ãã§ãUIWebViewãšåãåé¡ããããŸãã PDFã«é¢ããŠã¯ããã¹ãŠïŒããšãã°-99ïŒ
ïŒãéããŸãããèŠèŠçãªèª¿æŽãæ°ããæ©èœã®ãã蟌ã¿ã¯è¡ãããŸããã éåžžãããã°ã©ã ã«çµ±åããŠãæ©èœããŸããã
- PDFããã¥ã¡ã³ãã衚瀺ããããã®ãµãŒãããŒãã£ã®Objective-Cã©ã€ãã©ãªã¯ãiOSã®PDFãã¥ãŒã¢ã«å¿
èŠãªã»ãŒãã¹ãŠã®æ©èœãå®è£
ãã匷åãªã©ã€ãã©ãªã§ãã ããããããã§ããã«ã¹ã¿ãã€ãºãéåžžã«é«ãã³ã¹ãïŒ> 500 EURïŒãããã³Monotouchã§äœ¿çšããã©ãããŒãäœæããå¿
èŠããããšããåé¡ããããŸãããŸãããªãŒãã³ã¯ã©ã¹ãå€æ°ããã©ã€ãã©ãªã®å Žåãããã¯æãç°¡åãªã¿ã¹ã¯ã§ã¯ãããŸããã
çµå±ãç§ã¯å¿èïŒããããã®ã³ãŒããŒïŒãè²·ãã ãããããšã«æ±ºããŠãç§ã®åäœèªè»¢è»ãæžãå§ããŸããã ã©ã€ãã©ãªãäœæããåã«ããã®æ©èœã®ãªã¹ããå®çŸ©ããŸããã
- ããŒãžããããããã®2ã€ã®ãªãã·ã§ã³ã
- èªåããŒãžã¹ã±ãŒãªã³ã°ã
- å質ããŒãžã®è¡šç€ºã
- 詳现ãªããŒãžã¹ã±ãŒãªã³ã°ã
- ããã
- 泚ã
- ãµã ãã€ã«ã
- ãªãã·ã§ã³ãèšå®ããŸãã
- ãªã³ã¯ã®å®çŸ©ã
- æ€çŽ¢ã
- ææžã®å 容ãŸãã¯æ§é ãå®çŸ©ããŸãã
- Cocoa Touchã¯ã©ã¹ã®ã¿ã䜿çšããŠãã ããã
- 100Mb以äžã®ã倧ããªãããã¥ã¡ã³ãã®è¡šç€ºã
ãã¡ããã圌ã«ã¯æéããªããããã¹ãŠã®ã¢ã€ãã¢ãå®çŸã§ããŸããã§ããããããããã€ã圌ã®æãå±ãã§ãããã ãªã³ã¯ã®å®çŸ©ãšããã¥ã¡ã³ãã®ã³ã³ãã³ããããã³ããã¥ã¡ã³ãå ã®æ€çŽ¢ã¯ãŸã å®è£ ãããŠããŸããã
ããŒãžããã
æåã®ããããŠããããäž»ãªè³ªåã¯ãèŠèŠçãªããŒãžããããå®è£ ããæ¹æ³ã§ãããïŒ åè¿°ã®ãšãããPageControlã³ã³ããŒãã³ãã¯ãŸã ååšããŠããªãã£ããããç¬èªã®ãœãªã¥ãŒã·ã§ã³ãèæ¡ããå¿ èŠããããŸããã èããåŸãç§ã¯å€§ããªã³ã³ãã³ãé åãšãã®äžã®ããã€ãã®ãã¥ãŒã§æšæºã®ScrollViewã䜿çšããããšã«ããŸããã ScrollViewã䜿çšãããšãè€æ°ã®ãã¥ãŒãè¿œå ã§ããŸãã移åãããšãèŠèŠçã«çœ®ãæããããŸãïŒè£è¿ãã®å¹æã§ãïŒã ããã€ã®ãã¥ãŒãå¿ èŠã§ãããïŒ çãã¯ç°¡åã§ã-3ã€ïŒåã®ããŒãžã«1ã€ãçŸåšã®ããŒãžã«2ã€ã次ã®ããŒãžã«3ã€ïŒã ãã®å Žåã®ã³ã³ãã³ãé åã¯ã3 * View.Widthãã€ãŸã ããªãã«ããŒãžãã¥ãŒã®å¹ ã
æ°Žå¹³ããã³åçŽã®ããŒãžããããå®è£ ããŸããã å®éã®ã¹ã¯ããŒã«ã¯ãçŸåšã®ãã¥ãŒãå·ŠãŸãã¯äžïŒåæ¹ã«ã¹ã¯ããŒã«ããïŒããã³å³ãŸãã¯äžïŒåŸæ¹ã«ã¹ã¯ããŒã«ããïŒã«ãã©ãã°ãããšçºçããŸãã
ã¢ã«ãŽãªãºã ã¯ç°¡åã§ãã ãã®ããžãã¹ã¯ãã¹ãŠãUIScrollViewControllerã®åŸç¶ã§ããDocumentViewControllerã«å®è£ ãããŠããŸãã ãã¥ãŒãæ ŒçŽããããã«ãªã¹ãïŒé åã§ã¯ãªãïŒã䜿çšããŸãã çŸåšã®ãã¥ãŒã移åãããšïŒæ¬¡ã®ããŒãžãæåãŸãã¯æåŸã§ãªãå ŽåïŒãæ°ãããã¥ãŒãäœæãããŠãªã¹ãã«è¿œå ãããç®çã®PDFããŒãžãæ°ãããã¥ãŒã«ããŒããããæªäœ¿çšã®ãã¥ãŒïŒãªã¹ãã®æåïŒããªã¹ãããåé€ãããŸãã ããã«ãSrollView.Positionã¯äžå€®ã®è¡šç€ºäœçœ®ã«ã·ãããããŸãã ãã¥ãŒãªã¹ãã®2çªç®ã
public virtual void OpenDocumentPage(int pageNumber) { if (PDFDocument.DocumentHasLoaded && (pageNumber != PDFDocument.CurrentPageNumber)) { if ((pageNumber < 1) || (pageNumber > PDFDocument.PageCount)) { return; } // Set current page PDFDocument.CurrentPageNumber = pageNumber; // Calc min, max page int minValue; int maxValue; if (PDFDocument.PageCount <= MaxPageViewsCount) { minValue = 1; maxValue = PDFDocument.PageCount; } else { minValue = PDFDocument.CurrentPageNumber - 1; maxValue = PDFDocument.CurrentPageNumber + 1; if (minValue < 1) { minValue++; maxValue++; } else if (maxValue > PDFDocument.PageCount) { minValue--; maxValue--; } } // Create/update page views for displayed pages var unusedPageViews = new List<PageView>(mPageViews); RectangleF viewRect = GetScrollViewSubViewFrame(); for (int i = minValue, j = 0; i <= maxValue; i++,j++) { PageView pageView = mPageViews.FirstOrDefault(v => v.PageNumber == i); if (pageView == null) { pageView = new PageView(viewRect, i); mScrollView.AddSubview(pageView); mPageViews.Add(pageView); } else { pageView.Frame = viewRect; pageView.PageNumber = i; pageView.ZoomReset(); unusedPageViews.Remove(pageView); } viewRect = CalcFrameForNextPage(viewRect); if (i == PDFDocument.CurrentPageNumber) { mCurrentPageView = pageView; } } // Clear unused page views foreach (var view in unusedPageViews) { view.RemoveFromSuperview(); mPageViews.Remove(view); } // Update scroll view content offset UpdateScrollViewContentOffset(); } }
ããŒãžã®é«å質ãªè¡šç€ºãšã¹ã±ãŒãªã³ã°
ããŒãžã衚瀺ããããã®ãã¥ãŒã¯ãå®éã«ã¯3ã€ã®ãã¥ãŒã§æ§æãããŠããŸãã
- PageViewïŒUIScrollViewããç¶æ¿ïŒãDocumentViewControllerã«è¿œå ãããŸãã
- PageContentViewïŒUIViewããç¶æ¿ïŒãPageViewã«è¿œå ãããŸãã
- ThumbViewïŒUIPageViewããç¶æ¿ïŒãPageViewã«è¿œå ãããŸãã
æåã®ãã¥ãŒã¯ããŒãžãæ¡å€§çž®å°ããããã«å¿ èŠã§ããã2çªç®ã¯å®éã«ããŒãžã®é«å質衚瀺ã®ããã3çªç®ã¯ããŒãžã®äžæçãªç»åã®ããã«å¿ èŠã§ãã
ã¹ã±ãŒãªã³ã°æã®ããŒãžã®é«å質衚瀺ã®ããã«ãCATiledLayerã¯ã©ã¹ã®åå«ã䜿çšãããŸããã ãã®ã¯ã©ã¹ã䜿çšãããšããã¥ãŒãæ¡å€§ããªãã詳现ãªã³ã³ãã³ãã衚瀺ã§ããŸãã ãããããã¹ãŠã®è²»çšãæ¯æãå¿ èŠããããŸã-CATiledLayerã䜿çšãããšãããŒãžã®éåžžã«é·ãåæã¬ã³ããªã³ã°ïŒæ°ç§ïŒãçºçããäžå¿«ãªã¡ãã€ããçºçããå€ãç»åãæ°ããç»åã«æ®µéçã«çœ®ãæãããŸããã ãã®æªåœ±é¿ãåé¿ããããã«ãå¥ã®ãã¥ãŒ-ThumbViewãè¿œå ããŸãããããã«ãããäœè§£å床PDFããŒãžã®ãã©ã€ããªåºåãäœæããã次ã«ããŒãžã®ã¡ã€ã³ç»åã®åœ¢æãšåºåãè¡ãããŸããã
å®éã«PDFããŒãžèªäœã衚瀺ããã®ã¯éåžžã«ç°¡åã§ãã
private void Draw(CGContext context) { if (!PDFDocument.DocumentHasLoaded) { return; } // Draw page context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f); using (CGPDFPage pdfPage = PDFDocument.GetPage(mPageNumber)) { context.TranslateCTM(0, Bounds.Height); context.ScaleCTM(1.0f, -1.0f); context.ConcatCTM(pdfPage.GetDrawingTransform(CGPDFBox.Crop, Bounds, 0, true)); context.SetRenderingIntent(CGColorRenderingIntent.Default); context.InterpolationQuality = CGInterpolationQuality.Default; context.DrawPDFPage(pdfPage); } }
ããã¯ããŒã¯ãšã¡ã¢
ããã¥ã¡ã³ãã®ããã¯ããŒã¯ãšã¡ã¢ãæäœããããã®ã¯ã©ã¹ïŒãããŒãžã£ãŒïŒãèšèšãããšããéçºè ãããŒã¿ãä¿åããç¬èªã®ã¡ã«ããºã ãå®è£ ããæ©äŒãæäŸããããšèããŸããïŒXMLãããŒã¿ããŒã¹ãªã©ã«ãã©ã€ãã©ãªã䜿çšããç§ã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãããã¯ããŒã¯ãšã¡ã¢ã«é¢ããããŒã¿ãSqliteããŒã¿ããŒã¹ã«ä¿åããŸãã ãã¢ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãããŒã¿ã¯ã¢ããªã±ãŒã·ã§ã³ã®å®è¡äžã«ã¡ã¢ãªã«ä¿åãããŸãã
å®éãäž¡æ¹ã®ãããŒãžã£ãŒã¯äºãã«äŒŒãŠããŸãã ããŒã¿ãããŒããä¿åãåé€ããã¡ãœããããããŸãã ã»ãšãã©ã®ã¡ãœããã¯ä»®æ³ã§ãã ã¡ãœããã¯ãããããDocumentBookmarkãšDocumentNoteã®ããŒã¿ãªããžã§ã¯ããæäœããŸãã
ãªããªããMonotouchã«ã¯ããããŒãžã£ãŒãã¢ã¯ãã£ãã«ããã¡ã«ããºã ã§ãããžã§ããªãã¯åã®ãããªçŽ æŽããããã®ã¯ãªãããã§ããç§ã¯ãããããŸã奜ãã§ã¯ãããŸããã ã¢ããªã±ãŒã·ã§ã³ã®èµ·åæã«ãããŒãžã£ãŒãã€ã³ã¹ã¿ã³ã¹åããã¡ãœãããæã€ObjectActivatorã¯ã©ã¹ãäœæããŸããã ãããã£ãŠããããŒãžã£ãŒã¯ã©ã¹ã®ç¶æ¿ã®å Žåãæ°ããã€ã³ã¹ã¿ã³ã¹ãObjectActivatorã«ç»é²ããå¿ èŠããããŸãã
public class MyObjectsActivator : ObjectsActivator { /// <summary> /// Returns DocumentNoteManager instance /// </summary> /// <returns></returns> protected override DocumentNoteManager CreateDocumentNoteManager() { return new MyDocumentNoteManager(); } /// <summary> /// Returns DocumentBookmarkManager instance /// </summary> /// <returns></returns> protected override DocumentBookmarkManager CreateDocumentBookmarkManager() { return new MyDocumentBookmarkManager(); } }
ããŒãžã®ãµã ãã€ã«
ããŒãžã®ãµã ãã€ã«ã衚瀺ããã«ã¯ãããŒãžèªäœã衚瀺ããã®ãšåãã¢ãããŒãã䜿çšãããŸãããã ãããµã ãã€ã«ã®å Žåã¯ãäžåºŠã«è€æ°ã®ããŒãžã衚瀺ãããæ°ãããã¥ãŒãäœæããããã®ã¢ã«ãŽãªãºã ãå°ãç°ãªããŸãã ãŸãããµã ãã€ã«ã®ScrollViewã³ã³ãã³ãé åã®å¹ ã¯ããã¹ãŠã®ããŒãžã®ãµã ãã€ã«ã®å¹ ãšããã£ã³ã°ã®åèšã§ãã
æ£çŽãªãšããããµã ãã€ã«ã®è¡šç€ºããããå¿ èŠããããŸããã æåã«ããµã ãã€ã«ã®æ°ã衚瀺ããããµã ãã€ã«ã®æ°ã«çãããªãã¢ã«ãŽãªãºã ã«ãå·ŠåŽã«1ã€ãå³åŽã«1ã€ãå ããã¢ã«ãŽãªãºã ïŒã€ãŸããããŒãžè¡šç€ºãšãŸã£ããåæ§ã®ã¢ã«ãŽãªãºã ïŒãå®è£ ããããšããŸããã åæã«ãã¬ã³ããªã³ã°ãé«éåããããã«ã移åã®å察åŽã«ããããå€ãã®äžèŠãªãµã ãã€ã«ïŒé衚瀺ïŒã¯åé€ãããŸãããã移åã®æ¹åã«ç§»åãããŸãã ã€ãŸã ããã¯ããçš®ã®ãµã€ã¯ã«ã«ãªããŸãã ç§ã¯ãã®èããæšãŠãªããã°ãªããŸããã§ããããªããªã é«éãµã ãã€ã«ãã¹ã¯ããŒã«ããããšãScrolledã€ãã³ãã100ãã¯ã»ã«ä»¥äžã®ã®ã£ããã§çºçãããµã ãã€ã«éã«ãã®ã£ããããçããŸããã ééã£ãå Žæã«ã
ãã®çµæãçŸåšè¡šç€ºãããŠãããµã ãã€ã«ã¯åžžã«ãã®å Žæã«æ®ãã移åããå Žåã¯ãããã¡ãŒããã£ã±ãã«ãªã£ããšãã«ã®ã¿çœ®ãæããããããããã¡ãŒãã¢ã«ãŽãªãºã ã«æ±ºããŸããã ãããã¡ã®ãµã€ãºã¯ãªãã·ã§ã³ã§èšå®ãããŠãããããããã©ãŒãã³ã¹ãåäžãããã«ã¯ãåœç¶ã®ããšãªãããã¡ã¢ãªã®æ¶è²»éãå¢ããå¿ èŠããããŸãã
ãŸãšã
äžè¬çã«ãããã§ãã¹ãŠã§ãã質å/ã³ã¡ã³ã/ææ¡ããããŸããããã³ã¡ã³ããæžããŠãã ãããåãã§ãçãããŸãïŒãã¡ããã§ã¯ãããŸããïŒã
GitHubã©ã€ãã©ãªã®ãœãŒã¹ïŒ github.com/AlexanderMac/mTouch-PDFReader