123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- #import "CCControlCenter.h"
- #import "CCControlCenterTransfer.h"
- #import "CCControlCenterActivity.h"
- #import "AppDelegate.h"
- #import "CCMain.h"
- #import "CCDetail.h"
- #define BORDER_TOUCH_UPDOWN 50.0f
- #define TOOLBAR_ADD_BORDER 20.0f
- #define SIZE_FONT_NORECORD 18.0f
- #define ANIMATION_GESTURE 0.50f
- @interface CCControlCenter ()
- {
- UIVisualEffectView *_mainView;
- UIImageView *_imageDrag;
- UIView *_endLine;
-
- CGFloat start, stop;
-
- UIPanGestureRecognizer *panNavigationBar, *panImageDrag;
- UITapGestureRecognizer *_singleFingerTap;
-
- UIPageControl *pageControl;
- }
- @end
- @implementation CCControlCenter
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Init =====
- #pragma --------------------------------------------------------------------------------------------
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- if (self = [super initWithCoder:aDecoder]) {
-
- app.controlCenter = self;
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- _controlCenterPagesContent = [NSMutableArray new];
- UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
- _mainView = [[UIVisualEffectView alloc] initWithEffect:effect];
- [_mainView setFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, 0)];
- _mainView.hidden = YES;
-
-
-
-
-
- _pageType = @[k_pageControlCenterTransfer, k_pageControlCenterActivity];
-
-
- _pageViewController = [[UIStoryboard storyboardWithName: @"ControlCenter" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ControlCenterPageViewController"];
- _pageViewController.dataSource = self;
- _pageViewController.delegate = self;
-
- UIViewController *startingViewController;
- NSArray *viewControllers;
-
- startingViewController= [self viewControllerAtIndex:0];
- viewControllers = @[startingViewController];
- [_pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
-
- [_pageViewController.view setFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, 0)];
- _pageViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
-
- [_mainView addSubview:_pageViewController.view];
-
- _labelMessageNoRecord =[[UILabel alloc]init];
- _labelMessageNoRecord.backgroundColor=[UIColor clearColor];
- _labelMessageNoRecord.textColor = COLOR_CONTROL_CENTER;
- _labelMessageNoRecord.font = [UIFont systemFontOfSize:SIZE_FONT_NORECORD];
- _labelMessageNoRecord.textAlignment = NSTextAlignmentCenter;
- [_mainView addSubview:_labelMessageNoRecord];
-
-
- _imageDrag = [[UIImageView alloc] init];
- [_imageDrag setFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, 0)];
- _imageDrag.image = [UIImage imageNamed:image_drag];
- _imageDrag.contentMode = UIViewContentModeCenter;
- _imageDrag.userInteractionEnabled = YES;
- [_mainView addSubview:_imageDrag];
-
- _endLine = [[UIView alloc] init];
- [_endLine setFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, 0)];
- _endLine.backgroundColor = COLOR_CONTROL_CENTER;
- [_mainView addSubview:_endLine];
-
- [self.navigationBar.superview insertSubview:_mainView belowSubview:self.navigationBar];
-
-
- [self.interactivePopGestureRecognizer addTarget:self action:@selector(handlePopGesture:)];
-
- panImageDrag = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
- panImageDrag.maximumNumberOfTouches = panImageDrag.minimumNumberOfTouches = 1;
-
- [_imageDrag addGestureRecognizer:panImageDrag];
-
- panNavigationBar = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
- panNavigationBar.maximumNumberOfTouches = panNavigationBar.minimumNumberOfTouches = 1;
-
- [self.navigationBar addGestureRecognizer:panNavigationBar];
- }
- - (void)handlePanGesture:(UIPanGestureRecognizer *)gesture;
- {
- CGPoint currentPoint = [gesture locationInView:self.view];
- CGFloat navigationBarH = self.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
- CGFloat navigationBarW = self.navigationBar.frame.size.width;
- CGFloat heightScreen = [UIScreen mainScreen].bounds.size.height - self.tabBarController.tabBar.frame.size.height;
- CGFloat heightTableView = [UIScreen mainScreen].bounds.size.height - self.tabBarController.tabBar.frame.size.height - self.navigationBar.frame.size.height - BORDER_TOUCH_UPDOWN - TOOLBAR_ADD_BORDER;
- float centerMaxH = [self getMaxH] / 2;
- float step = [self getMaxH] / 10;
- float tableViewY = navigationBarH;
-
-
- _mainView.hidden = NO;
-
-
- if (gesture.state == UIGestureRecognizerStateBegan) {
-
- start = currentPoint.y;
- }
-
-
- if (gesture.state == UIGestureRecognizerStateCancelled) {
-
- currentPoint.y = 0;
- tableViewY = 0;
- panNavigationBar.enabled = YES;
- }
-
- if (gesture.state == UIGestureRecognizerStateEnded) {
-
- stop = currentPoint.y;
-
-
- if (start < stop) {
-
- if (stop < (start + step + navigationBarH) && start <= navigationBarH) {
- currentPoint.y = 0;
- tableViewY = 0;
- panNavigationBar.enabled = YES;
- } else {
- currentPoint.y = [self getMaxH];
- tableViewY = navigationBarH;
- panNavigationBar.enabled = NO;
- }
- }
-
-
- if (start >= stop && start >= navigationBarH) {
-
- if (stop > (start - step)) {
- currentPoint.y = [self getMaxH];
- tableViewY = navigationBarH;
- panNavigationBar.enabled = NO;
- } else {
- currentPoint.y = 0;
- tableViewY = 0;
- panNavigationBar.enabled = YES;
- }
- }
- }
-
-
- if (gesture.state == UIGestureRecognizerStateChanged) {
-
- if (currentPoint.y <= navigationBarH) {
- currentPoint.y = 0;
- tableViewY = 0;
- }
- else if (currentPoint.y >= [self getMaxH]) {
- currentPoint.y = [self getMaxH];
- tableViewY = navigationBarH;
- }
- else {
- if (currentPoint.y - navigationBarH < navigationBarH) tableViewY = currentPoint.y - navigationBarH;
- else tableViewY = navigationBarH;
- }
- }
-
- [UIView animateWithDuration:ANIMATION_GESTURE delay:0.0 options:UIViewAnimationOptionTransitionCrossDissolve
- animations:^ {
-
- _mainView.frame = CGRectMake(0, 0, navigationBarW, currentPoint.y);
- _pageViewController.view.frame = CGRectMake(0, currentPoint.y - heightScreen + navigationBarH, navigationBarW, heightTableView);
- _labelMessageNoRecord.frame = CGRectMake(0, currentPoint.y - centerMaxH, navigationBarW, SIZE_FONT_NORECORD+10);
- _imageDrag.frame = CGRectMake(0, currentPoint.y - BORDER_TOUCH_UPDOWN, navigationBarW, BORDER_TOUCH_UPDOWN);
- _endLine.frame = CGRectMake(0, currentPoint.y - BORDER_TOUCH_UPDOWN, navigationBarW, 1);
-
- } completion:^ (BOOL completed) {
-
- if (_mainView.frame.size.height == [self getMaxH]) {
- [self setIsOpen:YES];
- } else {
- [self setIsOpen:NO];
- }
-
-
- if (_mainView.frame.size.height == 0)
- _mainView.hidden = YES;
- }
- ];
- }
- - (void)handlePopGesture:(UIGestureRecognizer *)gesture
- {
- if (gesture.state == UIGestureRecognizerStateBegan) {
- _isPopGesture = YES;
- }
-
- if (gesture.state == UIGestureRecognizerStateEnded) {
- _isPopGesture = NO;
- }
- }
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
- {
- if (_isOpen) {
-
- [self setControlCenterHidden:YES];
-
- [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
-
- [self openControlCenterToSize];
-
- [self setControlCenterHidden: self.navigationBarHidden];
- }];
-
-
- }
-
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- }
- - (void)setControlCenterHidden:(BOOL)hidden
- {
- _mainView.hidden = hidden;
- }
- - (float)getMaxH
- {
-
-
- return [UIScreen mainScreen].bounds.size.height - self.tabBarController.tabBar.frame.size.height;
- }
- - (void)openControlCenterToSize
- {
- CGFloat navigationBarH = self.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
-
- _mainView.frame = CGRectMake(0, 0, self.navigationBar.frame.size.width, [self getMaxH]);
- _pageViewController.view.frame = CGRectMake(0, navigationBarH, _mainView.frame.size.width, _mainView.frame.size.height - self.navigationBar.frame.size.height - BORDER_TOUCH_UPDOWN - TOOLBAR_ADD_BORDER);
- _labelMessageNoRecord.frame = CGRectMake(0, _mainView.frame.size.height / 2, _mainView.frame.size.width, SIZE_FONT_NORECORD+10);
- _imageDrag.frame = CGRectMake(0, _mainView.frame.size.height - BORDER_TOUCH_UPDOWN, _mainView.frame.size.width, BORDER_TOUCH_UPDOWN);
- _endLine.frame = CGRectMake(0, _mainView.frame.size.height - BORDER_TOUCH_UPDOWN, _mainView.frame.size.width, 1);
-
- panNavigationBar.enabled = NO;
- [self setIsOpen:YES];
- }
- - (void)setIsOpen:(BOOL)setOpen
- {
- if (setOpen) {
-
- if (!_isOpen) {
-
- _isOpen = YES;
- [app.controlCenterTransfer reloadDatasource];
- [app.controlCenterActivity reloadDatasource];
- }
-
- } else {
-
- _isOpen = NO;
-
- }
-
- [self changeTabBarApplicationFileImage];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark - ===== Single Finger Tap =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)enableSingleFingerTap:(SEL)selector target:(id)target
- {
- _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:target action:selector];
- [self.navigationBar addGestureRecognizer:_singleFingerTap];
- }
- - (void)disableSingleFingerTap
- {
- [self.navigationBar removeGestureRecognizer:_singleFingerTap];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Page =====
- #pragma --------------------------------------------------------------------------------------------
- - (UIViewController *)viewControllerAtIndex:(NSUInteger)index
- {
- if (([self.pageType count] == 0) || (index >= [self.pageType count])) {
- return nil;
- }
-
- UIViewController *pageContentViewController;
-
- if ([self.controlCenterPagesContent count] >= index+1) {
-
- pageContentViewController = [self.controlCenterPagesContent objectAtIndex:index];
-
- } else {
-
- if (index == 0)
- pageContentViewController = [[UIStoryboard storyboardWithName: @"ControlCenter" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ControlCenterTransfer"];
-
- if (index == 1)
- pageContentViewController = [[UIStoryboard storyboardWithName: @"ControlCenter" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ControlCenterActivity"];
-
- [self.controlCenterPagesContent addObject:pageContentViewController];
- }
-
- ((CCControlCenterTransfer *) pageContentViewController).pageIndex = index;
- ((CCControlCenterTransfer *) pageContentViewController).pageType = self.pageType[index];
-
- return pageContentViewController;
- }
- - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
- {
- NSUInteger index = ((CCControlCenterTransfer *) viewController).pageIndex;
-
- if ((index == 0) || (index == NSNotFound)) {
- return nil;
- }
-
- index--;
- return [self viewControllerAtIndex:index];
- }
- - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
- {
- NSUInteger index = ((CCControlCenterTransfer *) viewController).pageIndex;
-
- if (index == NSNotFound) {
- return nil;
- }
-
- index++;
- if (index == [self.pageType count]) {
- return nil;
- }
- return [self viewControllerAtIndex:index];
- }
- - (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
- {
- return [self.pageType count];
- }
- - (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
- {
- return 0;
- }
- - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed
- {
- [self changeTabBarApplicationFileImage];
- }
- - (void)changeTabBarApplicationFileImage
- {
-
- if (!_isOpen) {
-
- self.title = NSLocalizedString(@"_home_", nil);
- UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexFile];
- item.selectedImage = [UIImage imageNamed:image_tabBarFile];
- item.image = [UIImage imageNamed:image_tabBarFile];
-
- return;
- }
-
-
- if ([[self getActivePage] isEqualToString:k_pageControlCenterActivity]) {
-
- self.title = NSLocalizedString(@"_activity_", nil);
-
- UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexFile];
- item.selectedImage = [UIImage imageNamed:image_tabBarActivity];
- item.image = [UIImage imageNamed:image_tabBarActivity];
-
- }
-
- if ([[self getActivePage] isEqualToString:k_pageControlCenterTransfer]) {
-
- self.title = NSLocalizedString(@"_transfers_", nil);
-
- UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexFile];
- item.selectedImage = [UIImage imageNamed:image_tabBarTransfer];
- item.image = [UIImage imageNamed:image_tabBarTransfer];
- }
- }
- - (NSString *)getActivePage
- {
- CCControlCenterTransfer *vc = [self.pageViewController.viewControllers lastObject];
-
- return vc.pageType;
- }
- @end
|