123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- //
- // PDFViewerModeViewController.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 "PDFViewerModeViewController.h"
- #import "PDFSettingsColorViewController.h"
- #import <ComPDFKit/ComPDFKit.h>
- @interface PDFViewerModeViewController () <UIPopoverPresentationControllerDelegate>
- @property (nonatomic,assign) IBOutlet UIScrollView *scrollView;
- @property (nonatomic,assign) IBOutlet UISlider *slider;
- @property (nonatomic,assign) IBOutlet UISegmentedControl *segmentedControl;
- @property (nonatomic,assign) IBOutlet UISwitch *switchButton;
- @end
- @implementation PDFViewerModeViewController
- #pragma mark - Init Methods
- - (void)dealloc {
- Block_release(_callback);
- [_color release];
- [super dealloc];
- }
- #pragma mark - UIViewController Methods
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // Do any additional setup after loading the view from its nib.
- self.preferredContentSize = CGSizeMake(320, 270);
-
- NSArray *colors = @[[UIColor whiteColor],
- [UIColor blackColor],
- [UIColor colorWithRed:255/255.0 green:239/255.0 blue:190/255.0 alpha:1.0],
- [UIColor colorWithRed:153.0/255.0 green:207.0/255.0 blue:161.0/255.0 alpha:1.0],
- [UIColor clearColor]];
-
- for (NSInteger i = 0; i < [colors count]; i++) {
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button addTarget:self action:@selector(buttonItemClicked_Color:) forControlEvents:UIControlEventTouchUpInside];
- button.tag = i;
- button.frame = CGRectMake(15+i*60, 5, 50.0, 50.0);
- button.layer.masksToBounds = YES;
- button.layer.cornerRadius = button.frame.size.width * 0.5;
- button.layer.borderWidth = 2.0;
- button.layer.borderColor = ((UIColor *)colors[i]).CGColor;
- button.showsTouchWhenHighlighted = YES;
- [button setBackgroundColor:colors[i]];
- if (i == self.themesType) {
- button.layer.borderColor = [UIColor colorWithRed:73.0/255.0 green:106.0/255.0 blue:239.0/255.0 alpha:1.0].CGColor;
- }
- if (i == [colors count]-1) {
- [button setBackgroundImage:[UIImage imageNamed:@"view_color_wheel_img.png"] forState:UIControlStateNormal];
- }
- [self.scrollView addSubview:button];
- }
-
- self.slider.value = self.brightness;
- self.segmentedControl.selectedSegmentIndex = self.scrollType;
- self.switchButton.on = self.isCropMode;
- }
- #pragma mark - Button Action
- - (void)buttonItemClicked_Color:(UIButton *)button {
- if (![[CPDFKit sharedInstance] allowsFeature:CPDFKitFeatureViewerRender]) {
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
- style:UIAlertActionStyleCancel
- handler:nil];
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
- message:NSLocalizedString(@"Your license does not support this feature, please upgrade your license privilege.", nil)
- preferredStyle:UIAlertControllerStyleAlert];
- [alert addAction:cancelAction];
- [self presentViewController:alert animated:YES completion:nil];
- return;
- }
-
- if (button.tag == 4) {
- CGRect rect = [self.view convertRect:button.frame fromView:button.superview];
- __block PDFSettingsColorViewController *vc = [[PDFSettingsColorViewController alloc] init];
- [vc setColor:self.color];
- vc.callback = ^{
- self.color = vc.color;
-
- for (UIButton *button in self.scrollView.subviews) {
- if ([button isKindOfClass:[UIButton class]]) {
- button.layer.borderColor = button.backgroundColor.CGColor;
- }
- }
- button.layer.borderColor = [UIColor colorWithRed:73.0/255.0 green:106.0/255.0 blue:239.0/255.0 alpha:1.0].CGColor;
-
- self.themesType = button.tag;
- if (self.callback) {
- self.callback(0);
- }
- };
- [vc showViewController:self inRect:rect];
- [vc release];
- } else {
- for (UIButton *button in self.scrollView.subviews) {
- if ([button isKindOfClass:[UIButton class]]) {
- button.layer.borderColor = button.backgroundColor.CGColor;
- }
- }
- button.layer.borderColor = [UIColor colorWithRed:73.0/255.0 green:106.0/255.0 blue:239.0/255.0 alpha:1.0].CGColor;
-
- self.themesType = button.tag;
- if (self.callback) {
- self.callback(0);
- }
- }
- }
- - (IBAction)sliderValueChanged_Brightness:(id)sender {
- self.brightness = self.slider.value;
- if (self.callback) {
- self.callback(1);
- }
- }
- - (IBAction)segmentedControlValueChanged_Mode:(id)sender {
- self.scrollType = self.segmentedControl.selectedSegmentIndex;
- if (self.callback) {
- self.callback(2);
- }
- }
- - (IBAction)switchValueChanged_CropMode:(id)sender {
- self.isCropMode = self.switchButton.isOn;
- if (self.callback) {
- self.callback(3);
- }
- }
- #pragma mark - Public Methods
- - (void)showViewController:(UIViewController *)viewController inBarButtonItem:(UIBarButtonItem *)barButtonItem {
- self.modalPresentationStyle = UIModalPresentationPopover;
- UIPopoverPresentationController *popVC = self.popoverPresentationController;
- popVC.delegate = self;
- popVC.barButtonItem = barButtonItem;
- popVC.permittedArrowDirections = UIPopoverArrowDirectionUp;
- [viewController presentViewController:self animated:YES completion:nil];
- }
- - (void)showViewController:(UIViewController *)viewController inRect:(CGRect)rect {
- self.modalPresentationStyle = UIModalPresentationPopover;
- UIPopoverPresentationController *popVC = self.popoverPresentationController;
- popVC.delegate = self;
- popVC.sourceRect = rect;
- popVC.sourceView = viewController.view;
- [viewController presentViewController:self animated:YES completion:nil];
- }
- #pragma mark - UIPopoverPresentationControllerDelegate
- - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
- return UIModalPresentationNone;
- }
- @end
|