Ver Fonte

PDFTools(iOS) - 移除懒加载

chenyu há 1 ano atrás
pai
commit
a5e5aeff5a

+ 23 - 36
compdfkit-tools/compdfkit-tools/Common/Controls/BOTA/CPDFBOTAViewController.m

@@ -35,48 +35,13 @@
 - (instancetype)initWithPDFView:(CPDFView *)pdfView {
     if (self = [super init]) {
         _pdfView = pdfView;
+        
     }
     return self;
 }
 
 #pragma mark - Accessors
 
-- (UISegmentedControl *)segmentedControl {
-    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
-    if (!_segmentedControl) {
-        NSArray *segmmentArray = [NSArray arrayWithObjects:NSLocalizedString(@"Thumbnail", nil), NSLocalizedString(@"Outline", nil), nil];
-        _segmentedControl = [[UISegmentedControl alloc] initWithItems:segmmentArray];
-        _segmentedControl.frame = CGRectMake(self.view.frame.size.width / 4, self.navigationController.navigationBar.frame.size.height + MIN(statusBarFrame.size.width, statusBarFrame.size.height) + 5 , self.view.frame.size.width / 2, 30);
-        [_segmentedControl addTarget:self action:@selector(segmentedControlValueChanged_BOTA:) forControlEvents:UIControlEventValueChanged];
-    }
-    _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
-    return _segmentedControl;
-}
-
-- (CPDFThumbnailViewController *)thumbnailViewController {
-    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
-    if (!_thumbnailViewController) {
-        _thumbnailViewController = [[CPDFThumbnailViewController alloc] initWithPDFView:self.pdfView];
-        _thumbnailViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
-        _thumbnailViewController.delegate = self;
-        [self addChildViewController:_thumbnailViewController];
-    }
-    _thumbnailViewController.view.frame = CGRectMake(0, self.navigationController.navigationBar.frame.size.height + MIN(statusBarFrame.size.width, statusBarFrame.size.height) + 45, self.view.bounds.size.width, self.view.bounds.size.height);
-    return _thumbnailViewController;
-}
-
-- (CPDFOutlineViewController *)outlineViewController {
-    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
-    if (!_outlineViewController) {
-        _outlineViewController = [[CPDFOutlineViewController alloc] initWithPDFView:self.pdfView];
-        _outlineViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
-        _outlineViewController.delegate = self;
-        [self addChildViewController:_outlineViewController];
-    }
-    _outlineViewController.view.frame = CGRectMake(0, self.navigationController.navigationBar.frame.size.height + MIN(statusBarFrame.size.width, statusBarFrame.size.height) + 45, self.view.bounds.size.width, self.view.bounds.size.height);
-
-    return _outlineViewController;
-}
 
 #pragma mark - UIViewController Methods
 
@@ -87,6 +52,28 @@
 
     self.view.backgroundColor = [CPDFColorUtils CPDFViewControllerBackgroundColor];
     
+    NSArray *segmmentArray = [NSArray arrayWithObjects:NSLocalizedString(@"Thumbnail", nil), NSLocalizedString(@"Outline", nil), nil];
+    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
+    self.segmentedControl = [[UISegmentedControl alloc] initWithItems:segmmentArray];
+    self.segmentedControl.frame = CGRectMake(self.view.frame.size.width / 4, self.navigationController.navigationBar.frame.size.height + MIN(statusBarFrame.size.width, statusBarFrame.size.height) + 5 , self.view.frame.size.width / 2, 30);
+    [self.segmentedControl addTarget:self action:@selector(segmentedControlValueChanged_BOTA:) forControlEvents:UIControlEventValueChanged];
+    self.segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
+    
+    
+    self.thumbnailViewController = [[CPDFThumbnailViewController alloc] initWithPDFView:self.pdfView];
+    self.thumbnailViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
+    self.thumbnailViewController.delegate = self;
+    [self addChildViewController:_thumbnailViewController];
+    
+    self.thumbnailViewController.view.frame = CGRectMake(0, self.navigationController.navigationBar.frame.size.height + MIN(statusBarFrame.size.width, statusBarFrame.size.height) + 45, self.view.bounds.size.width, self.view.bounds.size.height);
+    
+    
+    self.outlineViewController = [[CPDFOutlineViewController alloc] initWithPDFView:self.pdfView];
+    self.outlineViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
+    self.outlineViewController.delegate = self;
+        [self addChildViewController:_outlineViewController];
+    self.outlineViewController.view.frame = CGRectMake(0, self.navigationController.navigationBar.frame.size.height + MIN(statusBarFrame.size.width, statusBarFrame.size.height) + 45, self.view.bounds.size.width, self.view.bounds.size.height);
+    
     self.segmentedControl.selectedSegmentIndex = 0;
     [self.view addSubview:self.segmentedControl];
     

+ 13 - 0
compdfkit-tools/compdfkit-tools/Common/Views/PDFView/PDFSliderView/CPDFSlider.m

@@ -59,6 +59,19 @@
     if (self = [super init]) {
         _pdfView = pdfview;
         
+        self.valueView = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width-21, 0, 21, 69)];
+        self.valueView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
+        self.valueView.image = [UIImage imageNamed:@"CPDFSliderImageSlidepage" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
+        
+        self.label = [[UILabel alloc] init];
+        self.label.textAlignment = NSTextAlignmentCenter;
+        self.label.textColor = [UIColor blackColor];
+        self.label.backgroundColor = [UIColor whiteColor];
+        self.label.layer.cornerRadius = 2.0;
+        self.label.layer.borderWidth = 1.0;
+        self.label.layer.borderColor = [UIColor lightGrayColor].CGColor;
+        self.label.hidden = YES;
+        
         [self addSubview:self.label];
         [self addSubview:self.valueView];
     }

+ 7 - 13
compdfkit-tools/compdfkit-tools/Viewer/PDFMore/CPDFMoreListViewController.m

@@ -41,23 +41,17 @@
 
     self.title = NSLocalizedString(@"More",nil);
     
+    self.listView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
+    self.listView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
+    self.listView.delegate = self;
+    self.listView.dataSource = self;
+    self.listView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
+    self.listView.backgroundColor = [UIColor clearColor];
+    
     [self.view addSubview:self.listView];
     [self.listView reloadData];
 }
 
-- (UITableView *)listView{
-        
-    if (!_listView) {
-        _listView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
-        _listView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
-        _listView.delegate = self;
-        _listView.dataSource = self;
-        _listView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
-        _listView.backgroundColor = [UIColor clearColor];
-    }
-    return _listView;
-}
-
 - (NSArray *)itemArr{
     if(!_itemArr){
         _itemArr = [[NSArray alloc]initWithObjects:NSLocalizedString(@"File Info",nil), NSLocalizedString(@"Preview Setting",nil),nil];

+ 6 - 12
compdfkit-tools/compdfkit-tools/Viewer/PDFMore/PDFDisplaySetting/CPDFDisplayViewController.m

@@ -150,6 +150,12 @@ typedef NS_ENUM(NSUInteger, CDisplayPDFType) {
 - (void)viewDidLoad {
     [super viewDidLoad];
     
+    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
+    self.tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
+    self.tableView.delegate = self;
+    self.tableView.dataSource = self;
+    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
+    self.tableView.tableFooterView = [[UIView alloc] init];
     [self.view addSubview:self.tableView];
     [self.tableView reloadData];
     // Do any additional setup after loading the view.
@@ -157,18 +163,6 @@ typedef NS_ENUM(NSUInteger, CDisplayPDFType) {
 
 #pragma mark - Accessors
 
-- (UITableView *)tableView {
-    if (!_tableView) {
-        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
-        _tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
-        _tableView.delegate = self;
-        _tableView.dataSource = self;
-        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
-        _tableView.tableFooterView = [[UIView alloc] init];
-    }
-    return _tableView;
-}
-
 - (NSArray *)displayModeArray {
     if(!_displayModeArray) {
         _displayModeArray = @[@(CDisplayPDFTypeSinglePage),

+ 15 - 25
compdfkit-tools/compdfkit-tools/Viewer/PDFOutlie/CPDFOutlineViewController.m

@@ -41,31 +41,6 @@
 
 #pragma mark - Accessors
 
-- (UITableView *)tableView {
-    if (!_tableView) {
-        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
-        _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-        _tableView.delegate = self;
-        _tableView.dataSource = self;
-        _tableView.rowHeight = UITableViewAutomaticDimension;
-        _tableView.estimatedRowHeight = 60;
-        _tableView.tableFooterView = [[UIView alloc] init];
-    }
-    return _tableView;
-}
-
-- (UILabel *)noDataLabel {
-    if (!_noDataLabel) {
-        _noDataLabel = [[UILabel alloc] init];
-        _noDataLabel.textColor = [UIColor grayColor];
-        _noDataLabel.text = NSLocalizedString(@"No outlines", nil);
-        [_noDataLabel sizeToFit];
-        _noDataLabel.center = CGPointMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0);
-        _noDataLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
-    }
-    return _noDataLabel;
-}
-
 #pragma mark - UIViewController Methods
 
 - (void)loadOutline:(CPDFOutline *)outline level:(NSInteger)level forOutlines:(NSMutableArray *)outlines {
@@ -99,6 +74,21 @@
     [self loadOutline:outlineRoot level:0 forOutlines:array];
     self.outlines = array;
     
+    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
+    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+    self.tableView.delegate = self;
+    self.tableView.dataSource = self;
+    self.tableView.rowHeight = UITableViewAutomaticDimension;
+    self.tableView.estimatedRowHeight = 60;
+    self.tableView.tableFooterView = [[UIView alloc] init];
+    
+    self.noDataLabel = [[UILabel alloc] init];
+    self.noDataLabel.textColor = [UIColor grayColor];
+    self.noDataLabel.text = NSLocalizedString(@"No outlines", nil);
+    [self.noDataLabel sizeToFit];
+    self.noDataLabel.center = CGPointMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0);
+    self.noDataLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
+    
     [self.view addSubview:self.tableView];
     
     [self.view addSubview:self.noDataLabel];

+ 9 - 14
compdfkit-tools/compdfkit-tools/Viewer/PDFSearch/CPDFSearchResultsViewController.m

@@ -43,20 +43,6 @@
 
 #pragma mark - Accessors
 
-- (UITableView *)tableView{
-    if (!_tableView) {
-        _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
-        _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-        _tableView.delegate = self;
-        _tableView.dataSource = self;
-        _tableView.rowHeight = UITableViewAutomaticDimension;
-        _tableView.estimatedRowHeight = 60;
-        _tableView.tableFooterView = [[UIView alloc] init];
-        [_tableView registerClass:[CPDFSearchViewCell class] forCellReuseIdentifier:@"cell"];
-    }
-    return _tableView;
-}
-
 #pragma mark - UIViewController Methods
 
 - (void)viewDidLoad {
@@ -67,6 +53,15 @@
     
     self.title = NSLocalizedString(@"Search Results", nil);
     
+    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
+    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+    self.tableView.delegate = self;
+    self.tableView.dataSource = self;
+    self.tableView.rowHeight = UITableViewAutomaticDimension;
+    self.tableView.estimatedRowHeight = 60;
+    self.tableView.tableFooterView = [[UIView alloc] init];
+    [self.tableView registerClass:[CPDFSearchViewCell class] forCellReuseIdentifier:@"cell"];
+    
     [self.view addSubview:self.tableView];
 }
 

+ 17 - 21
compdfkit-tools/compdfkit-tools/Viewer/PDFThumbnail/CPDFThumbnailViewController.m

@@ -34,32 +34,28 @@
 
 #pragma mark - Accessors
 
-- (UICollectionView *)collectionView {
-    if (!_collectionView) {
-        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
-        layout.itemSize = CGSizeMake(110, 185);
-        layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
-        layout.minimumInteritemSpacing = 5;
-        layout.minimumLineSpacing = 5;
-        
-        _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
-        [_collectionView registerClass:[CPDFThumbnailViewCell class] forCellWithReuseIdentifier:@"cell"];
-        _collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
-        _collectionView.delegate = self;
-        _collectionView.dataSource = self;
-        _collectionView.alwaysBounceVertical = YES;
-        if (@available(iOS 11.0, *)) {
-            _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
-        }
-    }
-    return _collectionView;
-}
-
 #pragma mark - UIViewController Methods
 
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
+    
+    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
+    layout.itemSize = CGSizeMake(110, 185);
+    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
+    layout.minimumInteritemSpacing = 5;
+    layout.minimumLineSpacing = 5;
+    
+    self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
+    [self.collectionView registerClass:[CPDFThumbnailViewCell class] forCellWithReuseIdentifier:@"cell"];
+    self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
+    self.collectionView.delegate = self;
+    self.collectionView.dataSource = self;
+    self.collectionView.alwaysBounceVertical = YES;
+    if (@available(iOS 11.0, *)) {
+        _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
+    }
+    
     [self.view addSubview:self.collectionView];
 }