123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- //
- // PDFPageEditAddViewController.m
- // PDFReader
- //
- // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
- //
- // The PDF Reader Sample applications are licensed with a modified BSD license.
- // Please see License for details. This notice may not be removed from this file.
- //
- #import "PDFPageEditAddViewController.h"
- @interface PDFPageEditAddViewController () <UICollectionViewDelegate,UICollectionViewDataSource,UIPopoverPresentationControllerDelegate>
- @property (nonatomic,assign) IBOutlet UICollectionView *collectionView;
- @property (nonatomic,retain) NSMutableArray *pages;
- @end
- @implementation PDFPageEditAddViewController
- #pragma mark - Init Methods
- - (instancetype)init {
- if (self = [super init]) {
-
- }
- return self;
- }
- - (void)dealloc {
- Block_release(_callback);
- [_pages release];
- [super dealloc];
- }
- #pragma mark - UIViewController Methods
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- self.title = NSLocalizedString(@"New Page", nil);
-
- [self.collectionView registerClass:[PDFPageEditCell class] forCellWithReuseIdentifier:@"PDFPageEditCell"];
- self.collectionView.alwaysBounceVertical = YES;
-
- self.pages = [NSMutableArray array];
- NSArray *images = @[@"", @"paper1@2x", @"paper2@2x", @"paper3@2x", @"paper4@2x", @"paper5@2x", @"paper6@2x",];
- for (int i=0; i<images.count; i++) {
- NSString *image = images[i];
- PDFEditPage *page = [[PDFEditPage alloc] init];
- if (image.length > 0) {
- NSString *imagePath = [[NSBundle mainBundle] pathForResource:image ofType:@"jpg"];
- page.imagePath = imagePath;
- }
- if (i > 3) {
- page.size = CGSizeMake(842, 595);
- }
- [self.pages addObject:page];
- [page release];
- }
- }
- #pragma mark - Public Methods
- - (void)showViewController:(UIViewController *)viewController inBarButtonItem:(UIBarButtonItem *)barButtonItem {
- if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
- self.preferredContentSize = CGSizeMake(580, 580);
- } else {
- self.preferredContentSize = CGSizeMake(280, 280);
- }
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self];
- nav.modalPresentationStyle = UIModalPresentationPopover;
- UIPopoverPresentationController *popVC = nav.popoverPresentationController;
- popVC.delegate = self;
- popVC.barButtonItem = barButtonItem;
- popVC.permittedArrowDirections = UIPopoverArrowDirectionUp;
- [viewController presentViewController:nav animated:YES completion:nil];
- [nav release];
- }
- #pragma mark - UIPopoverPresentationControllerDelegate
- - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
- return UIModalPresentationNone;
- }
- #pragma mark - UICollectionViewDelegateFlowLayout
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
- return CGSizeMake(180, 180);
- } else {
- return CGSizeMake(80, 80);
- }
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.pages.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- PDFPageEditCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PDFPageEditCell" forIndexPath:indexPath];
- cell.backgroundColor = [UIColor clearColor];
- cell.page = self.pages[indexPath.item];
- return cell;
- }
- #pragma mark - UICollectionViewDelegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- [self dismissViewControllerAnimated:YES completion:^{
- if (self.callback) {
- self.callback(self.pages[indexPath.item]);
- self.callback = nil;
- }
- }];
- }
- @end
|