Skip to content

Commit

Permalink
Merge pull request #12 from doPanic/master
Browse files Browse the repository at this point in the history
fixes and extensions
  • Loading branch information
Marxon13 committed Aug 23, 2015
2 parents 976da11 + 51c0538 commit 273653c
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 64 deletions.
52 changes: 52 additions & 0 deletions Classes/View/PDFKBasicPDFViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#import <UIKit/UIKit.h>
@class PDFKDocument;
@class PDFKPageScrubber;
@class PDFKBasicPDFViewerSinglePageCollectionView;
@class PDFKBasicPDFViewerThumbsCollectionView;

typedef void (^PDFKBasicPDFViewerPageChangeBlock)(NSUInteger page);

Expand Down Expand Up @@ -81,5 +84,54 @@ typedef void (^PDFKBasicPDFViewerPageChangeBlock)(NSUInteger page);
*/
@property (nonatomic, assign) BOOL standalone;

/**
The toolbar displaied at the top of the screen.
*/
@property (nonatomic, retain, readonly) UIToolbar *navigationToolbar;
/**
The slider at the bottom of the screen to show the thumbnails.
*/
@property (nonatomic, retain, readonly) UIToolbar *thumbnailSlider;
/**
The popover controller to share the document on the iPad.
*/
@property (nonatomic, strong, readonly) UIPopoverController *activityPopoverController;
/**
The share button.
*/
@property (nonatomic, strong, readonly) UIBarButtonItem *shareItem;
/**
The item that notes wether or not the page is bookmarked.
*/
@property (nonatomic, strong, readonly) UIBarButtonItem *bookmarkItem;
/**
The page scrubber at the bottom of the view.
*/
@property (nonatomic, strong, readonly) PDFKPageScrubber *pageScrubber;
/**
The collection view of single pages to display.
*/
@property (nonatomic, strong, readonly) PDFKBasicPDFViewerSinglePageCollectionView *pageCollectionView;
/**
Wether or not the view is showing a single page.
*/
@property (nonatomic, assign, readonly) BOOL showingSinglePage;
/**
The collection view that displays all the thumbs.
*/
@property (nonatomic, strong, readonly) PDFKBasicPDFViewerThumbsCollectionView *thumbsCollectionView;
/**
Wether or not the thumbs collection view is showing thumbs.
*/
@property (nonatomic, assign, readonly) BOOL showingBookmarks;
/**
YES once view did load called.
*/
@property (nonatomic, assign, readonly) BOOL loadedView;

/**
title of the button for going back from thumbnail-view to page-view
*/
@property (nonatomic, strong) NSString *backButtonTitle;

@end
80 changes: 26 additions & 54 deletions Classes/View/PDFKBasicPDFViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,27 @@
#import "PDFKBasicPDFViewerSinglePageCollectionView.h"
#import <TTOpenInAppActivity/TTOpenInAppActivity.h>


@interface PDFKBasicPDFViewer () <UIToolbarDelegate, UIDocumentInteractionControllerDelegate, PDFKPageScrubberDelegate, UIGestureRecognizerDelegate, PDFKBasicPDFViewerThumbsCollectionViewDelegate, PDFKBasicPDFViewerSinglePageCollectionViewDelegate>

/**
The toolbar displaied at the top of the screen.
*/
@property (nonatomic, retain) UIToolbar *navigationToolbar;
/**
The slider at the bottom of the screen to show the thumbnails.
*/
@property (nonatomic, retain) UIToolbar *thumbnailSlider;
/**
The popover controller to share the document on the iPad.
*/
@property (nonatomic, strong) UIPopoverController *activityPopoverController;
/**
The share button.
*/
@property (nonatomic, strong) UIBarButtonItem *shareItem;
/**
The item that notes wether or not the page is bookmarked.
*/
@property (nonatomic, strong) UIBarButtonItem *bookmarkItem;
/**
The page scrubber at the bottom of the view.
*/
@property (nonatomic, strong) PDFKPageScrubber *pageScrubber;
/**
The collection view of single pages to display.
*/
@property (nonatomic, strong) PDFKBasicPDFViewerSinglePageCollectionView *pageCollectionView;
/**
Wether or not the view is showing a single page.
*/
@property (nonatomic, assign) BOOL showingSinglePage;
/**
The collection view that displays all the thumbs.
*/
@property (nonatomic, strong) PDFKBasicPDFViewerThumbsCollectionView *thumbsCollectionView;
/**
Wether or not the thumbs collection view is showing thumbs.
*/
@property (nonatomic, assign) BOOL showingBookmarks;
/**
YES once view did load called.
*/
@property (nonatomic, assign) BOOL loadedView;
@property (nonatomic, retain, readwrite) UIToolbar *navigationToolbar;
@property (nonatomic, retain, readwrite) UIToolbar *thumbnailSlider;
@property (nonatomic, strong, readwrite) UIPopoverController *activityPopoverController;
@property (nonatomic, strong, readwrite) UIBarButtonItem *shareItem;
@property (nonatomic, strong, readwrite) UIBarButtonItem *bookmarkItem;
@property (nonatomic, strong, readwrite) PDFKPageScrubber *pageScrubber;
@property (nonatomic, strong, readwrite) PDFKBasicPDFViewerSinglePageCollectionView *pageCollectionView;
@property (nonatomic, assign, readwrite) BOOL showingSinglePage;
@property (nonatomic, strong, readwrite) PDFKBasicPDFViewerThumbsCollectionView *thumbsCollectionView;
@property (nonatomic, assign, readwrite) BOOL showingBookmarks;
@property (nonatomic, assign, readwrite) BOOL loadedView;

@property (nonatomic, strong) UITapGestureRecognizer *singleTapGestureRecognizer;
@property (nonatomic, strong) UITapGestureRecognizer *doubleTapGestureRecognizer;

@end


@implementation PDFKBasicPDFViewer

#pragma mark - Initalization and Loading
Expand Down Expand Up @@ -290,15 +259,6 @@ - (void)resetNavigationToolbar
UIBarButtonItem *listItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Thumbs"] landscapeImagePhone:[UIImage imageNamed:@"Thumbs"] style:UIBarButtonItemStylePlain target:self action:@selector(list)];
[buttonsArray addObject:listItem];

//Sharing Button
if (_enableSharing || _enablePrinting || _enableOpening) {
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
space.width = 10.0;
[buttonsArray addObject:space];
_shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(send)];
[buttonsArray addObject:_shareItem];
}

//Flexible space
[buttonsArray addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]];

Expand All @@ -318,6 +278,15 @@ - (void)resetNavigationToolbar

[buttonsArray addObject:_bookmarkItem];
}

//Sharing Button
if (_enableSharing || _enablePrinting || _enableOpening) {
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
space.width = 10.0;
[buttonsArray addObject:space];
_shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(send)];
[buttonsArray addObject:_shareItem];
}
} else {

//Set controls for thumbs
Expand All @@ -335,7 +304,10 @@ - (void)resetNavigationToolbar
}

//Go back
UIBarButtonItem *listItem = [[UIBarButtonItem alloc] initWithTitle:@"Resume" style:UIBarButtonItemStylePlain target:self action:@selector(list)];
if (!self.backButtonTitle) {
self.backButtonTitle = @"Resume";
}
UIBarButtonItem *listItem = [[UIBarButtonItem alloc] initWithTitle:self.backButtonTitle style:UIBarButtonItemStylePlain target:self action:@selector(list)];
[buttonsArray addObject:listItem];

//Flexible space
Expand Down
13 changes: 12 additions & 1 deletion Classes/View/PDFKPageScrubber.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@
*/
@property (nonatomic, weak, readwrite) id <PDFKPageScrubberDelegate> scrubberDelegate;

/**
The scrubber's page number label – use for styling.
*/
@property (nonatomic, strong) UILabel *pageNumberLabel;

/**
the background color of the thumb
defaults to [UIColor colorWithWhite:0.8 ...]
*/
@property (nonatomic, strong) UIColor *thumbBackgroundColor;

/**
Initalize the scrubber with the given frame and document.
Expand Down Expand Up @@ -98,6 +109,6 @@
@return A new thumb view.
*/
- (id)initWithFrame:(CGRect)frame small:(BOOL)small;
- (id)initWithFrame:(CGRect)frame small:(BOOL)small andColor:(UIColor *)color;

@end
19 changes: 13 additions & 6 deletions Classes/View/PDFKPageScrubber.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ @implementation PDFKPageScrubber
NSTimer *trackTimer;
}

@synthesize pageNumberLabel = pageNumberLabel;

- (id)initWithFrame:(CGRect)frame
{
return [self initWithFrame:frame document:nil];
Expand Down Expand Up @@ -144,6 +146,12 @@ - (id)initWithFrame:(CGRect)frame document:(PDFKDocument *)object
return self;
}

- (UIColor *)thumbBackgroundColor {
if (!_thumbBackgroundColor) {
return [UIColor colorWithWhite:0.8 alpha:1];
}
return _thumbBackgroundColor;
}

- (void)removeFromSuperview
{
Expand Down Expand Up @@ -241,7 +249,7 @@ - (void)layoutSubviews
CGRect thumbRect = CGRectMake(thumbX, thumbY, THUMB_LARGE_WIDTH, THUMB_LARGE_HEIGHT);

//Create the thumb view
pageThumbView = [[PDFKPageScrubberThumb alloc] initWithFrame:thumbRect];
pageThumbView = [[PDFKPageScrubberThumb alloc] initWithFrame:thumbRect small:NO andColor:self.thumbBackgroundColor];
//Z position so that it sits on top of the small thumbs
pageThumbView.layer.zPosition = 1.0f;
//Add as the first subview of the track control
Expand Down Expand Up @@ -289,7 +297,7 @@ - (void)layoutSubviews
NSString *phrase = document.password;

//Create a small thumb view
smallThumbView = [[PDFKPageScrubberThumb alloc] initWithFrame:thumbRect small:YES];
smallThumbView = [[PDFKPageScrubberThumb alloc] initWithFrame:thumbRect small:YES andColor:self.thumbBackgroundColor];
PDFKThumbRequest *thumbRequest = [PDFKThumbRequest newForView:smallThumbView fileURL:fileURL password:phrase guid:guid page:page size:size];

//Request the thumb
Expand Down Expand Up @@ -525,16 +533,15 @@ @implementation PDFKPageScrubberThumb

- (id)initWithFrame:(CGRect)frame
{
return [self initWithFrame:frame small:NO];
return [self initWithFrame:frame small:NO andColor:[UIColor colorWithWhite:0.8 alpha:0]];
}

- (id)initWithFrame:(CGRect)frame small:(BOOL)small
- (id)initWithFrame:(CGRect)frame small:(BOOL)small andColor:(UIColor *)color
{
if ((self = [super initWithFrame:frame]))
{
CGFloat value = (small ? 0.6f : 0.7f); // Size based alpha value

UIColor *background = [UIColor colorWithWhite:0.8f alpha:value];
UIColor *background = [color colorWithAlphaComponent:value];

self.backgroundColor = background;
imageView.backgroundColor = background;
Expand Down
6 changes: 3 additions & 3 deletions M13PDFKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "M13PDFKit"
s.version = "1.0.3"
s.version = "1.1.0"
s.summary = "M13PDFKit is an iBooks like PDF viewer that can be embedded in iOS applications."

s.description = <<-DESC
Expand All @@ -27,11 +27,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

s.platform = :ios, '8.0'

s.source = { :git => "https://github.com/Marxon13/M13PDFKit.git", :tag => "v1.0.3"}
s.source = { :git => "https://github.com/Marxon13/M13PDFKit.git", :tag => "v1.1.0"}

s.source_files = 'Classes/**/*.{h,m}'

s.ios.resource_bundle = { 'M13PDFKitResources' => 'Resources/*' }
s.ios.resource_bundle = { 'M13PDFKitResources' => 'Resources/*.png' }

s.frameworks = 'Foundation', 'CoreGraphics', 'ImageIO', 'UIKit'

Expand Down
56 changes: 56 additions & 0 deletions M13PDFKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

/* Begin PBXBuildFile section */
186C7FBB404D4DA5AD113882 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 88CCBC2FFD064D688D11FAD6 /* libPods.a */; };
99FD8AAE1B4569AA0082331C /* Bookmark.png in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AA21B4569AA0082331C /* Bookmark.png */; };
99FD8AAF1B4569AA0082331C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AA31B4569AA0082331C /* [email protected] */; };
99FD8AB01B4569AA0082331C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AA41B4569AA0082331C /* [email protected] */; };
99FD8AB11B4569AA0082331C /* Bookmarked.png in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AA51B4569AA0082331C /* Bookmarked.png */; };
99FD8AB21B4569AA0082331C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AA61B4569AA0082331C /* [email protected] */; };
99FD8AB31B4569AA0082331C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AA71B4569AA0082331C /* [email protected] */; };
99FD8AB41B4569AA0082331C /* PageList.png in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AA81B4569AA0082331C /* PageList.png */; };
99FD8AB51B4569AA0082331C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AA91B4569AA0082331C /* [email protected] */; };
99FD8AB61B4569AA0082331C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AAA1B4569AA0082331C /* [email protected] */; };
99FD8AB71B4569AA0082331C /* Thumbs.png in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AAB1B4569AA0082331C /* Thumbs.png */; };
99FD8AB81B4569AA0082331C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AAC1B4569AA0082331C /* [email protected] */; };
99FD8AB91B4569AA0082331C /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 99FD8AAD1B4569AA0082331C /* [email protected] */; };
CA784DA21A1F99A6003F953B /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA784DA11A1F99A6003F953B /* ImageIO.framework */; };
CA86CE8C1A1EAF45009CDD7C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA86CE8B1A1EAF45009CDD7C /* CoreGraphics.framework */; };
CA86CE901A1EAF56009CDD7C /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA86CE8F1A1EAF56009CDD7C /* MessageUI.framework */; };
Expand Down Expand Up @@ -48,6 +60,18 @@
/* Begin PBXFileReference section */
3BC96A8F8D1C3AA80967EB3F /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
88CCBC2FFD064D688D11FAD6 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
99FD8AA21B4569AA0082331C /* Bookmark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Bookmark.png; path = Resources/Bookmark.png; sourceTree = SOURCE_ROOT; };
99FD8AA31B4569AA0082331C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/[email protected]"; sourceTree = SOURCE_ROOT; };
99FD8AA41B4569AA0082331C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/[email protected]"; sourceTree = SOURCE_ROOT; };
99FD8AA51B4569AA0082331C /* Bookmarked.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Bookmarked.png; path = Resources/Bookmarked.png; sourceTree = SOURCE_ROOT; };
99FD8AA61B4569AA0082331C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/[email protected]"; sourceTree = SOURCE_ROOT; };
99FD8AA71B4569AA0082331C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/[email protected]"; sourceTree = SOURCE_ROOT; };
99FD8AA81B4569AA0082331C /* PageList.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = PageList.png; path = Resources/PageList.png; sourceTree = SOURCE_ROOT; };
99FD8AA91B4569AA0082331C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/[email protected]"; sourceTree = SOURCE_ROOT; };
99FD8AAA1B4569AA0082331C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/[email protected]"; sourceTree = SOURCE_ROOT; };
99FD8AAB1B4569AA0082331C /* Thumbs.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Thumbs.png; path = Resources/Thumbs.png; sourceTree = SOURCE_ROOT; };
99FD8AAC1B4569AA0082331C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/[email protected]"; sourceTree = SOURCE_ROOT; };
99FD8AAD1B4569AA0082331C /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Resources/[email protected]"; sourceTree = SOURCE_ROOT; };
9B73E826AFCCB1D55EC99EF8 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
CA784DA11A1F99A6003F953B /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
CA86CE8B1A1EAF45009CDD7C /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -139,6 +163,25 @@
name = Pods;
sourceTree = "<group>";
};
99FD8ABA1B4569AE0082331C /* Images */ = {
isa = PBXGroup;
children = (
99FD8AA21B4569AA0082331C /* Bookmark.png */,
99FD8AA31B4569AA0082331C /* [email protected] */,
99FD8AA41B4569AA0082331C /* [email protected] */,
99FD8AA51B4569AA0082331C /* Bookmarked.png */,
99FD8AA61B4569AA0082331C /* [email protected] */,
99FD8AA71B4569AA0082331C /* [email protected] */,
99FD8AA81B4569AA0082331C /* PageList.png */,
99FD8AA91B4569AA0082331C /* [email protected] */,
99FD8AAA1B4569AA0082331C /* [email protected] */,
99FD8AAB1B4569AA0082331C /* Thumbs.png */,
99FD8AAC1B4569AA0082331C /* [email protected] */,
99FD8AAD1B4569AA0082331C /* [email protected] */,
);
name = Images;
sourceTree = "<group>";
};
CAF256291A1CFF0000F0EA4F = {
isa = PBXGroup;
children = (
Expand All @@ -163,6 +206,7 @@
isa = PBXGroup;
children = (
CAF2565B1A1CFF2C00F0EA4F /* Classes */,
99FD8ABA1B4569AE0082331C /* Images */,
CAF256391A1CFF0000F0EA4F /* AppDelegate.h */,
CAF2563A1A1CFF0000F0EA4F /* AppDelegate.m */,
CA86CE911A1EB311009CDD7C /* SamplesTableViewController.h */,
Expand Down Expand Up @@ -344,9 +388,21 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
99FD8AB71B4569AA0082331C /* Thumbs.png in Resources */,
99FD8AB91B4569AA0082331C /* [email protected] in Resources */,
CA86CE971A1EB561009CDD7C /* Wikipedia.pdf in Resources */,
99FD8AB01B4569AA0082331C /* [email protected] in Resources */,
99FD8AAF1B4569AA0082331C /* [email protected] in Resources */,
99FD8AB31B4569AA0082331C /* [email protected] in Resources */,
99FD8AAE1B4569AA0082331C /* Bookmark.png in Resources */,
99FD8AB11B4569AA0082331C /* Bookmarked.png in Resources */,
99FD8AB21B4569AA0082331C /* [email protected] in Resources */,
CAF256411A1CFF0000F0EA4F /* Main.storyboard in Resources */,
99FD8AB41B4569AA0082331C /* PageList.png in Resources */,
CAF256431A1CFF0100F0EA4F /* Images.xcassets in Resources */,
99FD8AB81B4569AA0082331C /* [email protected] in Resources */,
99FD8AB61B4569AA0082331C /* [email protected] in Resources */,
99FD8AB51B4569AA0082331C /* [email protected] in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 273653c

Please sign in to comment.