|
@@ -6,6 +6,7 @@
|
|
|
//
|
|
|
|
|
|
#import "CPDFHeaderFooterAddController.h"
|
|
|
+#import "CPDFAddViewControllerHeader.h"
|
|
|
|
|
|
@interface CPDFHeaderFooterAddController ()
|
|
|
|
|
@@ -20,75 +21,18 @@
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
- // Do any additional setup after loading the view.
|
|
|
- // Setting navigation
|
|
|
- [self initNavigation];
|
|
|
-
|
|
|
- // Initialize show label
|
|
|
- [self initShowLabel];
|
|
|
-
|
|
|
- // Initialize model
|
|
|
- [self initModel];
|
|
|
-
|
|
|
- // Add page image
|
|
|
- [self initIamge];
|
|
|
-
|
|
|
- // Add view
|
|
|
- [self initBttonmView];
|
|
|
-
|
|
|
// UI event
|
|
|
- [self initBasicEvent];
|
|
|
-
|
|
|
[self initExtendEvent];
|
|
|
}
|
|
|
|
|
|
#pragma mark - Initializers
|
|
|
|
|
|
-- (void)initNavigation {
|
|
|
- self.navigationItem.title = @"Add Page NUmber";
|
|
|
- self.navigationController.toolbarHidden = YES;
|
|
|
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneClick:)];
|
|
|
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelClick:)];
|
|
|
-}
|
|
|
-
|
|
|
-- (id)initWithIamge:(UIImage *)image WithSize:(CGSize)size {
|
|
|
- self = [super init];
|
|
|
- if (self) {
|
|
|
- _image = image;
|
|
|
- _size = size;
|
|
|
- }
|
|
|
- return self;
|
|
|
-}
|
|
|
-
|
|
|
- (void)initModel {
|
|
|
- _modelData = [[CPDFHeaderFooterModel alloc] init];
|
|
|
- _modelData.fontSize = 18.0;
|
|
|
- _modelData.fontSelcet = 0;
|
|
|
- _modelData.fontPosition = 1;
|
|
|
- _modelData.pageStart = @"1";
|
|
|
-}
|
|
|
-
|
|
|
-- (void)initShowLabel {
|
|
|
- _showLabel = [[UILabel alloc] init];
|
|
|
- [_showLabel setText:@"1"];
|
|
|
- _showLabel.font = [UIFont systemFontOfSize:6];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)initIamge {
|
|
|
- _imageView = [[UIImageView alloc] init];
|
|
|
-
|
|
|
- _imageView.image = self.image;
|
|
|
- CALayer *layer = [_imageView layer];
|
|
|
- layer.borderColor = [[UIColor blackColor] CGColor];
|
|
|
- layer.borderWidth = 1.0f;
|
|
|
- [self.view addSubview:_imageView];
|
|
|
-
|
|
|
- [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(self.view.mas_top).offset(125);
|
|
|
- make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.size.width / 6));
|
|
|
- make.width.mas_equalTo(self.size.width / 3);
|
|
|
- make.height.mas_equalTo(self.size.height / 3);
|
|
|
- }];
|
|
|
+ self.modelData = [[CPDFHeaderFooterModel alloc] init];
|
|
|
+ self.modelData.fontSize = 18.0;
|
|
|
+ self.modelData.fontSelcet = 0;
|
|
|
+ self.modelData.fontPosition = 0;
|
|
|
+ self.modelData.pageStart = @"1";
|
|
|
}
|
|
|
|
|
|
- (void)initBttonmView {
|
|
@@ -96,12 +40,25 @@
|
|
|
[_headerFooterview setText];
|
|
|
[self.view addSubview:_headerFooterview];
|
|
|
|
|
|
- [self.headerFooterview mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(self.imageView.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);
|
|
|
- }];
|
|
|
+
|
|
|
+ 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 {
|
|
@@ -114,6 +71,12 @@
|
|
|
[_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;
|
|
|
}
|
|
|
|
|
@@ -143,23 +106,37 @@
|
|
|
[self.headerFooterview addSubview:self.pageFormat];
|
|
|
[self.view bringSubviewToFront:self.pageFormat];
|
|
|
[_pageFormat mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(self.headerFooterview.mas_top).offset(50);
|
|
|
- make.left.equalTo(self.headerFooterview.mas_left).offset(50);
|
|
|
- make.width.mas_equalTo(293);
|
|
|
- make.height.mas_equalTo(300);
|
|
|
+ make.top.equalTo(self.headerFooterview.mas_top);
|
|
|
+ make.left.equalTo(self.headerFooterview.mas_left);
|
|
|
+ make.width.mas_equalTo(393);
|
|
|
+ make.height.mas_equalTo(400);
|
|
|
}];
|
|
|
|
|
|
- // Tablevire animation
|
|
|
- [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
|
|
|
- NSLog(@"animations");
|
|
|
- self.pageFormat.center = CGPointMake(self.pageFormat.center.x + 150 + [UIScreen mainScreen].bounds.size.width / 2, self.pageFormat.center.y);
|
|
|
- } completion:^(BOOL finished) {
|
|
|
- NSLog(@"completion");
|
|
|
- }];
|
|
|
+ // 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;
|
|
|
}
|
|
@@ -183,11 +160,11 @@
|
|
|
#pragma mark - UITableViewDelegate
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
- self.headerFooterview.pageNumberText.text = self.dataArray[indexPath.row];
|
|
|
|
|
|
self.modelData.fontSelcet = indexPath.row;
|
|
|
|
|
|
- self.showLabel.text = self.dataArray[indexPath.row];
|
|
|
+ self.headView.showLabel.text = self.dataArray[indexPath.row];
|
|
|
+ [self showPages];
|
|
|
}
|
|
|
|
|
|
#pragma mark - Actions
|
|
@@ -207,6 +184,7 @@
|
|
|
}
|
|
|
|
|
|
- (void)pageFormatOk:(UIButton *)okBtn {
|
|
|
+ self.headerFooterview.pageNumberText.text = self.headView.showLabel.text;
|
|
|
[self.pageFormat removeFromSuperview];
|
|
|
}
|
|
|
|
|
@@ -221,145 +199,42 @@
|
|
|
// Get headerfoote's font size for headerfooter's Model
|
|
|
- (void)changeFontSize:(UITextField *)text {
|
|
|
float size = [text.text floatValue];
|
|
|
- _showLabel.font = [UIFont systemFontOfSize:size / 3];
|
|
|
- _modelData.fontSize = size;
|
|
|
+ self.headView.showLabel.font = [UIFont systemFontOfSize:size / 3];
|
|
|
+ self.modelData.fontSize = size;
|
|
|
}
|
|
|
|
|
|
-// Slider select color
|
|
|
-- (void)sliderChange:(UISlider *)slider {
|
|
|
- switch ((int)slider.value / 10) {
|
|
|
- case 0:
|
|
|
- self.showLabel.textColor = [UIColor redColor];
|
|
|
- self.modelData.fontColor = [UIColor redColor];
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- self.showLabel.textColor = [UIColor orangeColor];
|
|
|
- self.modelData.fontColor = [UIColor orangeColor];
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- self.showLabel.textColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1];
|
|
|
- self.modelData.fontColor = [UIColor colorWithRed:239.0 / 255 green:140.0 / 255 blue:133.0 / 255 alpha:1];
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- self.showLabel.textColor = [UIColor yellowColor];
|
|
|
- self.modelData.fontColor = [UIColor yellowColor];;
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- self.showLabel.textColor = [UIColor greenColor];
|
|
|
- self.modelData.fontColor = [UIColor greenColor];
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- self.showLabel.textColor = [UIColor blueColor];
|
|
|
- self.modelData.fontColor = [UIColor blueColor];
|
|
|
- break;
|
|
|
- case 6:
|
|
|
- self.showLabel.textColor = [UIColor purpleColor];
|
|
|
- self.modelData.fontColor = [UIColor purpleColor];
|
|
|
- break;
|
|
|
- case 7:
|
|
|
- self.showLabel.textColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1];
|
|
|
- self.modelData.fontColor = [UIColor colorWithRed:235.0 / 255 green:61.0 / 255 blue:133.0 / 255 alpha:1];
|
|
|
- break;
|
|
|
- case 8:
|
|
|
- self.showLabel.textColor = [UIColor blackColor];
|
|
|
- self.modelData.fontColor = [UIColor blackColor];
|
|
|
- break;
|
|
|
- case 9:
|
|
|
- self.showLabel.textColor = [UIColor whiteColor];
|
|
|
- self.modelData.fontColor = [UIColor whiteColor];
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// Select headerfooter
|
|
|
-- (void)changeLocation:(UISegmentedControl *)sender {
|
|
|
- if (sender.selectedSegmentIndex == 0) {
|
|
|
- _position.location = kHeader;
|
|
|
+- (void)viewUp {
|
|
|
+ if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) {
|
|
|
+
|
|
|
} else {
|
|
|
- _position.location = kFooter;
|
|
|
+ [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];
|
|
|
}
|
|
|
- [self showPages];
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-// Select aligment
|
|
|
-- (void)changeAligbment:(UISegmentedControl *)sender {
|
|
|
- if (sender.selectedSegmentIndex == 0) {
|
|
|
- _position.aligment = kLeft;
|
|
|
- } else if (sender.selectedSegmentIndex == 1) {
|
|
|
- _position.aligment = kCenter;
|
|
|
+- (void)viewDown {
|
|
|
+ if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) {
|
|
|
+
|
|
|
} else {
|
|
|
- _position.aligment = kRinght;
|
|
|
- }
|
|
|
- [self showPages];
|
|
|
-}
|
|
|
-
|
|
|
-// Show headerfooter and aligment
|
|
|
-- (void)showPages {
|
|
|
- if (_showLabel == nil) {
|
|
|
- _showLabel = [[UILabel alloc] init];
|
|
|
- }
|
|
|
- [self.imageView addSubview:self.showLabel];
|
|
|
-
|
|
|
- switch (self.position.location) {
|
|
|
- case kHeader:
|
|
|
- if (self.position.aligment == kLeft) {
|
|
|
- [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(_imageView.mas_top).offset(0.5);
|
|
|
- make.left.equalTo(self.imageView.mas_left).offset(0.5);
|
|
|
- make.height.mas_equalTo(10);
|
|
|
- make.width.mas_equalTo(20);
|
|
|
- }];
|
|
|
- self.modelData.fontPosition = 0;
|
|
|
- } else if (self.position.aligment == kCenter) {
|
|
|
- [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(_imageView.mas_top).offset(0.5);
|
|
|
- make.left.equalTo(self.imageView.mas_left).offset(self.size.width / 6);
|
|
|
- make.height.mas_equalTo(10);
|
|
|
- make.width.mas_equalTo(20);
|
|
|
- }];
|
|
|
- self.modelData.fontPosition = 1;
|
|
|
- } else {
|
|
|
- [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(self.imageView.mas_top).offset(0.5);
|
|
|
- make.left.equalTo(self.imageView.mas_left).offset(self.size.width / 3 - 12);
|
|
|
- make.height.mas_equalTo(10);
|
|
|
- make.width.mas_equalTo(20);
|
|
|
- }];
|
|
|
- self.modelData.fontPosition = 2;
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case kFooter:
|
|
|
- if (self.position.aligment == kLeft) {
|
|
|
- [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(self.imageView.mas_top).offset(self.size.height / 3 - 12);
|
|
|
- make.left.equalTo(self.imageView.mas_left).offset(0.5);
|
|
|
- make.height.mas_equalTo(10);
|
|
|
- make.width.mas_equalTo(20);
|
|
|
- }];
|
|
|
- self.modelData.fontPosition = 3;
|
|
|
- } else if (self.position.aligment == kCenter) {
|
|
|
- [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(self.imageView.mas_top).offset(self.size.height / 3 - 12);
|
|
|
- make.left.equalTo(self.imageView.mas_left).offset(self.size.width/6);
|
|
|
- make.height.mas_equalTo(10);
|
|
|
- make.width.mas_equalTo(20);
|
|
|
- }];
|
|
|
- self.modelData.fontPosition = 4;
|
|
|
- } else {
|
|
|
- [_showLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(self.imageView.mas_top).offset(self.size.height / 3 - 12);
|
|
|
- make.left.equalTo(self.imageView.mas_left).offset(self.size.width / 3 - 12);
|
|
|
- make.height.mas_equalTo(10);
|
|
|
- make.width.mas_equalTo(20);
|
|
|
- }];
|
|
|
- self.modelData.fontPosition = 5;
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ [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];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -368,11 +243,11 @@
|
|
|
// When orientation
|
|
|
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
|
|
if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
|
|
|
- [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.top.equalTo(self.view.mas_top).offset((393 / 2) - (self.size.height / 6));
|
|
|
- make.left.equalTo(self.view.mas_left).offset((393 / 2) - (self.size.width/6));
|
|
|
- make.width.mas_equalTo(self.size.width / 3);
|
|
|
- make.height.mas_equalTo(self.size.height / 3);
|
|
|
+ [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) {
|
|
@@ -381,17 +256,16 @@
|
|
|
make.width.mas_equalTo(393);
|
|
|
make.height.mas_equalTo(self.view.frame.size.height - 20);
|
|
|
}];
|
|
|
-
|
|
|
} else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
|
|
|
- [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ [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.size.width / 6));
|
|
|
- make.width.mas_equalTo(self.size.width / 3);
|
|
|
- make.height.mas_equalTo(self.size.height / 3);
|
|
|
+ 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.imageView.mas_bottom).offset(60);
|
|
|
+ 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);
|