123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- //
- // HeaderFooterAlertViewController.m
- // PDFViewer
- //
- // Created by kdanmobile_2 on 2022/11/16.
- //
- #import "CPDFHeaderFooterAddController.h"
- #import "CPDFAddViewControllerHeader.h"
- @interface CPDFHeaderFooterAddController ()
- @property (nonatomic,strong) CPDFHeaderFooterAddView *headerFooterview;
- @property (nonatomic,strong) CPDFHeaderFooterTextTableView *pageFormat;
- @property (nonatomic,strong) NSMutableArray *dataArray;
- @end
- @implementation CPDFHeaderFooterAddController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // UI event
- [self initExtendEvent];
- }
- #pragma mark - Initializers
- - (void)initModel {
- self.modelData = [[CPDFHeaderFooterModel alloc] init];
- self.modelData.fontSize = 18.0;
- self.modelData.fontSelcet = 0;
- self.modelData.fontPosition = 0;
- self.modelData.pageStart = @"1";
- }
- - (void)initBttonmView {
- _headerFooterview = [[CPDFHeaderFooterAddView alloc] init];
- [_headerFooterview setText];
- [self.view addSubview:_headerFooterview];
-
-
- if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
- [self.headerFooterview mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view.mas_top).offset(15);
- make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width / 2);
- make.width.mas_equalTo(393);
- make.height.mas_equalTo(self.view.frame.size.height - 20);
- }];
- } else {
- [self.headerFooterview mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.headView.mas_bottom).offset(60);
- make.left.equalTo(self.view.mas_left);
- make.width.mas_equalTo(self.view.frame.size.width);
- make.height.mas_equalTo(self.view.frame.size.height);
- }];
- }
-
- self.headerFooterview.localSegment.selectedSegmentIndex = 0;
- self.headerFooterview.aligbmentSegment.selectedSegmentIndex = 0;
- }
- - (void)initBasicEvent {
- [_headerFooterview.localSegment addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventValueChanged];
- [_headerFooterview.aligbmentSegment addTarget:self action:@selector(changeAligbment:) forControlEvents:UIControlEventValueChanged];
- [_headerFooterview.colorSlider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
- }
- - (void)initExtendEvent {
- [_headerFooterview.fontSizeText addTarget:self action:@selector(changeFontSize:) forControlEvents:UIControlEventEditingChanged];
- [_headerFooterview.pageIndexNumberText addTarget:self action:@selector(changePageStart:) forControlEvents:UIControlEventEditingChanged];
-
- [_headerFooterview.fontSizeText addTarget:self action:@selector(viewUp) forControlEvents:UIControlEventEditingDidBegin];
- [_headerFooterview.pageIndexNumberText addTarget:self action:@selector(viewUp) forControlEvents:UIControlEventEditingDidBegin];
-
- [_headerFooterview.fontSizeText addTarget:self action:@selector(viewDown) forControlEvents:UIControlEventEditingDidEnd];
- [_headerFooterview.pageIndexNumberText addTarget:self action:@selector(viewDown) forControlEvents:UIControlEventEditingDidEnd];
-
- _headerFooterview.pageNumberText.delegate = self;
- }
- #pragma mark - Accessors
- - (NSArray *)dataArray {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- NSArray *pageFormatArray = [[NSArray alloc] initWithObjects:@"1",@"page 1",@"1/n",@"1 of n",@"page 1 of n",nil];
-
- for (int i = 0; i < pageFormatArray.count; i++) {
- [_dataArray addObject:pageFormatArray[i]];
- }
- }
- return _dataArray;
- }
- #pragma mark - UITextFieldDelegate
- // TableView initialize
- - (void)textFieldDidBeginEditing:(UITextField *)textField {
- _pageFormat = [[CPDFHeaderFooterTextTableView alloc] initWithTitleName:@"Format Selection"];
-
- _pageFormat.tableView.delegate = self;
- _pageFormat.tableView.dataSource = self;
-
- [self.headerFooterview addSubview:self.pageFormat];
- [self.view bringSubviewToFront:self.pageFormat];
- [_pageFormat mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.headerFooterview.mas_top);
- make.left.equalTo(self.headerFooterview.mas_left);
- make.width.mas_equalTo(393);
- make.height.mas_equalTo(400);
- }];
-
- // Tableview animation
- [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
- self.pageFormat.center = CGPointMake(self.pageFormat.center.x - 200 - [UIScreen mainScreen].bounds.size.width / 2, self.pageFormat.center.y);
- } completion:nil];
-
- [self.pageFormat.okBtn addTarget:self action:@selector(pageFormatOk:) forControlEvents:UIControlEventTouchUpInside];
- }
- - (void)textFieldDidChangeSelection:(UITextField *)textField {
-
- [self.headerFooterview addSubview:self.pageFormat];
- [self.view bringSubviewToFront:self.pageFormat];
- [_pageFormat mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.headerFooterview.mas_top);
- make.left.equalTo(self.headerFooterview.mas_left);
- make.width.mas_equalTo(393);
- make.height.mas_equalTo(400);
- }];
-
- // Tableview animation
- [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
- self.pageFormat.center = CGPointMake(self.pageFormat.center.x - 200 - [UIScreen mainScreen].bounds.size.width / 2, self.pageFormat.center.y);
- } completion:nil];
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- return NO;
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pageFormat"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pageFormat"];
- }
-
- cell.textLabel.text = self.dataArray[indexPath.row];
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- self.modelData.fontSelcet = indexPath.row;
-
- self.headView.showLabel.text = self.dataArray[indexPath.row];
- [self showPages];
- }
- #pragma mark - Actions
- // Candel button enable
- - (void)cancelClick:(UIBarButtonItem *)btn {
- [self.navigationController popViewControllerAnimated:YES];
- }
- // Done button enable
- - (void)doneClick:(UIBarButtonItem *)btn {
- if ([self.delegate respondsToSelector:@selector(changeHeaderFooterModelData:)]) {
- [self.delegate changeHeaderFooterModelData:self.modelData];
- }
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)pageFormatOk:(UIButton *)okBtn {
- self.headerFooterview.pageNumberText.text = self.headView.showLabel.text;
- [self.pageFormat removeFromSuperview];
- }
- #pragma mark - UI Functions
- // Get page start for headerfooter's Model
- - (void)changePageStart:(UITextField *)text {
- int start = [text.text intValue];
- self.modelData.pageStart = [NSString stringWithFormat:@"%d",start];
- }
- // Get headerfoote's font size for headerfooter's Model
- - (void)changeFontSize:(UITextField *)text {
- float size = [text.text floatValue];
- self.headView.showLabel.font = [UIFont systemFontOfSize:size / 3];
- self.modelData.fontSize = size;
- }
- - (void)viewUp {
- if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) {
-
- } else {
- [self.headerFooterview mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view).offset(125);
- make.left.equalTo(self.view.mas_left);
- make.width.mas_equalTo(self.view.frame.size.width);
- make.height.mas_equalTo(self.view.frame.size.height);
- }];
-
- [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
- self.headerFooterview.center = CGPointMake(self.headerFooterview.center.x, self.headerFooterview.center.y - 300);
- } completion:nil];
- }
-
- }
- - (void)viewDown {
- if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) {
-
- } else {
- [self.headerFooterview mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.headView.mas_bottom).offset(60);
- make.left.equalTo(self.view.mas_left);
- make.width.mas_equalTo(self.view.frame.size.width);
- make.height.mas_equalTo(self.view.frame.size.height);
- }];
-
- [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
- self.headerFooterview.center = CGPointMake(self.headerFooterview.center.x, self.headerFooterview.center.y + 300);
- } completion:nil];
- }
- }
- #pragma mark - Orientation
- // When orientation
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
- if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
- [self.headView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view.mas_top).offset((393 / 2) - (self.image.size.height / 18));
- make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.image.size.width / 18));
- make.width.mas_equalTo(self.image.size.width / 9);
- make.height.mas_equalTo(self.image.size.height / 9);
- }];
-
- [self.headerFooterview mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view.mas_top).offset(15);
- make.left.equalTo(self.view.mas_left).offset(self.view.frame.size.width / 2 + 200);
- make.width.mas_equalTo(393);
- make.height.mas_equalTo(self.view.frame.size.height - 20);
- }];
- } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
- [self.headView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view.mas_top).offset(125);
- make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.image.size.width / 18));
- make.width.mas_equalTo(self.image.size.width / 9);
- make.height.mas_equalTo(self.image.size.height / 9);
- }];
-
- [self.headerFooterview mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.headView.mas_bottom).offset(60);
- make.left.equalTo(self.view.mas_left);
- make.width.mas_equalTo(self.view.frame.size.width);
- make.height.mas_equalTo(self.view.frame.size.height);
- }];
- }
- }
- @end
|