123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- //
- // BatesAddViewController.m
- // PDFViewer
- //
- // Created by kdanmobile_2 on 2022/11/18.
- //
- #import "CPDFBatesAddViewController.h"
- #import "CPDFAddViewControllerHeader.h"
- @interface CPDFBatesAddViewController ()
- @property (nonatomic,strong) CPDFHeaderFooterTextTableView *fontName;
- @property (nonatomic,strong) NSMutableArray *dataArray;
- @property (nonatomic,strong) CPDFBatesAddView *batesAddView;
- @end
- @implementation CPDFBatesAddViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self initExtendEvent];
- }
- #pragma mark - Initializers
- - (void)initNavigation {
- self.navigationItem.title = @"Add Bates";
- self.navigationController.toolbarHidden = YES;
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBatesClick:)];
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick:)];
- }
- - (void)initModel {
- self.modelData = [[CPDFHeaderFooterModel alloc] init];
- self.modelData.fontName = @"Helvetica";
- self.modelData.fontPosition = 0;
- self.modelData.fontText = @"#2#1#0#0";
- self.modelData.fontColor = [UIColor blackColor];
- }
- - (void)initBttonmView {
- _batesAddView = [[CPDFBatesAddView alloc] init];
- [_batesAddView setText];
- [self.view addSubview:_batesAddView];
- self.headView.showLabel.text = @"0010";
-
- if (([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) || ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) || ([UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) || (self.view.frame.size.width > self.view.frame.size.height)) {
- [self.batesAddView 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.batesAddView 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.batesAddView.localSegment.selectedSegmentIndex = 0;
- self.batesAddView.aligbmentSegment.selectedSegmentIndex = 0;
- }
- - (void)initBasicEvent {
- [_batesAddView.localSegment addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventValueChanged];
- [_batesAddView.aligbmentSegment addTarget:self action:@selector(changeAligbment:) forControlEvents:UIControlEventValueChanged];
- [_batesAddView.colorSlider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
- }
- - (void)initExtendEvent {
- [_batesAddView.pageIndexNumberText addTarget:self action:@selector(changePageStart:) forControlEvents:UIControlEventEditingChanged];
- [_batesAddView.pageNumberText addTarget:self action:@selector(changeText:) forControlEvents:UIControlEventEditingChanged];
-
- [_batesAddView.pageNumberText addTarget:self action:@selector(viewUp) forControlEvents:UIControlEventEditingDidBegin];
- [_batesAddView.pageIndexNumberText addTarget:self action:@selector(viewUp) forControlEvents:UIControlEventEditingDidBegin];
-
- [_batesAddView.pageNumberText addTarget:self action:@selector(viewDown) forControlEvents:UIControlEventEditingDidEnd];
- [_batesAddView.pageIndexNumberText addTarget:self action:@selector(viewDown) forControlEvents:UIControlEventEditingDidEnd];
-
- _batesAddView.fontNameText.delegate = self;
- }
- #pragma mark - Accessors
- - (NSArray *)dataArray {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- NSArray *fontNameArray = [[NSArray alloc] initWithObjects:@"Helvetica",@"Arial",@"Arial Rounded MT Bold", @"Arial Unicode MS",@"Courier",nil];
-
- for (int i = 0; i < fontNameArray.count; i++) {
- [_dataArray addObject:fontNameArray[i]];
- }
- }
- return _dataArray;
- }
- #pragma mark - UITextFieldDelegate
- - (void)textFieldDidBeginEditing:(UITextField *)textField {
- _fontName = [[CPDFHeaderFooterTextTableView alloc] initWithTitleName:@"Font Name"];
-
- _fontName.tableView.delegate = self;
- _fontName.tableView.dataSource = self;
-
- [self.batesAddView addSubview:self.fontName ];
- [self.view bringSubviewToFront:self.fontName];
- [_fontName mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.batesAddView.mas_top);
- make.left.equalTo(self.batesAddView.mas_left);
- make.width.mas_equalTo(393);
- make.height.mas_equalTo(400);
- }];
-
- // Tableview animation
- [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
- self.fontName.center = CGPointMake(self.fontName.center.x - 200 - [UIScreen mainScreen].bounds.size.width / 2, self.fontName.center.y);
- } completion:^(BOOL finished) {
- NSLog(@"completion");
- }];
-
- [self.fontName.okBtn addTarget:self action:@selector(fontNameOk:) forControlEvents:UIControlEventTouchUpInside];
- }
- - (void)textFieldDidChangeSelection:(UITextField *)textField {
-
- [self.batesAddView addSubview:self.fontName];
- [self.view bringSubviewToFront:self.fontName];
- [_fontName mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.batesAddView.mas_top);
- make.left.equalTo(self.batesAddView.mas_left);
- make.width.mas_equalTo(393);
- make.height.mas_equalTo(400);
- }];
-
- // Tableview animation
- [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
- self.fontName.center = CGPointMake(self.fontName.center.x - 200 - [UIScreen mainScreen].bounds.size.width / 2, self.fontName.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.fontName = self.dataArray[indexPath.row];
-
- self.headView.showLabel.font = [UIFont fontWithName:self.dataArray[indexPath.row] size:5];
- }
- #pragma mark - Actions
- // Done button enable
- - (void)doneBatesClick:(UIBarButtonItem *)btn {
- if ([self.delegate respondsToSelector:@selector(changBatesModelData:)]) {
- [self.delegate changBatesModelData:self.modelData];
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- // Candel button enable
- - (void)cancelClick:(UIBarButtonItem *)btn {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)fontNameOk:(UIButton *)okBtn {
- self.batesAddView.fontNameText.text = self.modelData.fontName;
-
- [_fontName removeFromSuperview];
- }
- #pragma mark - UI Functions
- // Get page text for bates's model
- - (void)changeText:(UITextField *)text {
- NSArray *textArray = [text.text componentsSeparatedByString:@"#"];
- NSString *showText = [[NSString alloc] init];
-
- if (text.text.length >= 2) {
- int i = [textArray[1] intValue];
- for (int j = 0; j < i-1; j++) {
- NSString *test = showText;
- showText = [NSString stringWithFormat:@"%d%@",0,test];
- }
- }
- if (text.text.length >= 4) {
- showText = [NSString stringWithFormat:@"%@%@",showText,textArray[2]];
- }
- if (text.text.length >= 6) {
- showText = [NSString stringWithFormat:@"%@%@",textArray[3],showText];
- }
- if (text.text.length == 8) {
- showText = [NSString stringWithFormat:@"%@%@",showText,textArray[4]];
- }
-
- self.headView.showLabel.text = showText;
- self.modelData.fontText = text.text;
- }
- // Get page text start for bates's model
- - (void)changePageStart:(UITextField *)text {
- int start = [text.text intValue];
- self.modelData.pageStart = [NSString stringWithFormat:@"%d",start - 1];
- }
- - (void)viewUp {
- [self.batesAddView 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.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.center.y - 300);
- } completion:nil];
- }
- - (void)viewDown {
- [self.batesAddView 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.batesAddView.center = CGPointMake(self.batesAddView.center.x, self.batesAddView.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.batesAddView 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.batesAddView 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
|