// // orderController.m // ThePaperDemo // // Created by scar1900 on 14-9-29. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "orderController.h" #import "AppDelegate.h" #import "SCGIFImageView.h" #import "nodeInfoController.h" #import "nodeInfoCell.h" #import "CoreAnimationEffect.h" #import "LBorderView.h" #import "searchController.h" #import "loginHomeController.h" #import "leakController.h" #define ORDERBUTTONTAG 6000 #define ORDEREDVIEWTAG 6500 @interface orderController() { NSString* isUserSystemFont; NSMutableArray *colorArray; CGFloat btnHeight; } @property(nonatomic, strong)UIImageView *orderImageView; @property(nonatomic, strong)UIButton *searchBtn;//搜索 @property(nonatomic, strong)UIButton *leakBtn; //报料 @property(nonatomic, strong)UIView *lineView; @property(nonatomic, strong)UIView *nodeBtnView; //订阅侧边栏 @property(nonatomic, strong)NSMutableArray *orderButtonArray; @property(nonatomic, strong)NSMutableArray *nodeListArray; //@property(nonatomic, strong)SCGIFImageView *waitCursor; //@property(nonatomic, strong)UIView *waitBackView; @property(nonatomic, strong)UIView *colorView; @property(nonatomic, strong)nodeInfoController *nodeInfoController; @property(nonatomic, assign)NSInteger currentIndex; @property(nonatomic, strong)UILongPressGestureRecognizer *longGesture; @property(nonatomic, strong)UIView *orderedView; //订阅拖动后的View @property(nonatomic, strong)LBorderView *orderLineView; //拖动后的虚线 @property(nonatomic, strong)NSMutableArray *orderChildList; @end @implementation orderController @synthesize orderButtonArray; @synthesize nodeListArray = _nodeListArray; @synthesize currentIndex = _currentIndex; @synthesize longGesture; @synthesize orderChildList=_orderChildList; - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [self.view addSubview:self.searchBtn]; [self.view addSubview:self.leakBtn]; if (rect_screen.size.height>960/2) { btnHeight = 145/2; }else { btnHeight = 60; } /** * bug:5374(【适配性】栏目导航页:“订阅”显示不全,详情见图) */ UIView *btnLine = [UIView new]; btnLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [self.view addSubview:btnLine]; CGFloat offset = 0; if (isIOS7) offset = 9; [btnLine makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.searchBtn.centerY).offset(offset); make.width.equalTo(@1); make.height.equalTo(@18); make.right.equalTo(self.searchBtn.right); }]; // if (isIOS7) { // _searchBarView.frame = CGRectMake(0, 0, rect_screen.size.width-50, 156/2); // }else { // _searchBarView.frame = CGRectMake(0, 0, rect_screen.size.width-50, 60); // } self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; isUserSystemFont = [TPUserDefault instance].isUseSystemFont; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAfterOpenNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.searchBtn.titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); self.leakBtn.titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); needGestureOfSideController(YES); NSMutableArray *channelList = [TPUserDefault instance].channldataList; NSDictionary *currentDic = channelList[[TPUserDefault instance].currentPageIndex]; __block NSInteger curIndex = -1; curIndex = self.currentIndex; [self.nodeListArray enumerateObjectsUsingBlock:^(nodeObjectBO* obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj.nodeId intValue] == [currentDic[@"nodeId"] intValue]) { curIndex = idx; } }]; if ([TPUserDefault instance].userBO && curIndex == 5) { [self remoteAskOrderData]; return; } if (!self.nodeListArray || self.nodeListArray.count == 0) { NSError *error; NSFetchRequest *request = [[NSFetchRequest alloc]init]; //为已创建好的实体利用检索到的上下文创建一个实体描述 NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"NodeListDB" inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext]; [request setEntity:entityDescription]; NodeListDB *nodeListDB = nil; NSArray *objs = [[CoreDataManager shareInstance].managedObjectContext executeFetchRequest:request error:&error]; if (objs == nil) { TPLOG(@"there was an error!!"); } if (objs.count > 0) { nodeListDB = [objs objectAtIndex:0]; NSDictionary *coreDataDic = makeCoreDataModelToDic(nodeListDB, [NodeListDB class]); self.nodeListArray = [NSMutableArray array]; if (coreDataDic && coreDataDic[@"nodeList"]) { NSArray *nodeArray = coreDataDic[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { nodeObjectBO *nodeInfo = setJsonDicToDataModel(obj, [nodeObjectBO class]); [tempArray addObject:nodeInfo]; }]; self.nodeListArray = tempArray; } } [self askForRemoteNodeList]; }else { if ([isUserSystemFont intValue] != [[TPUserDefault instance].isUseSystemFont intValue]) { [self.nodeInfoController.collectionView reloadData]; isUserSystemFont = [TPUserDefault instance].isUseSystemFont; for (int i=0;i<5;i++) { UIButton *orderBtn = (UIButton*)[self.nodeBtnView viewWithTag:6000+i]; if (orderBtn) { orderBtn.titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); } } } self.orderedView.hidden = NO; nodeObjectBO *nodeInfo = self.nodeListArray[self.currentIndex]; if ([nodeInfo.nodeId intValue] == -1) { nodeInfo.myOrderStatus = @"2"; self.orderChildList = [NSMutableArray array]; self.nodeInfoController.orderNodeBO = nodeInfo; self.nodeInfoController.nodeList = self.orderChildList; } if (curIndex < 0) { return; } UIButton *orderBtn = (UIButton*)[self.nodeBtnView viewWithTag:ORDERBUTTONTAG+curIndex]; [self orderClickHandler:orderBtn]; /** * bug:5163(栏目页的频道未与正文的频道同步) */ } } //获取网络栏目信息 - (void)askForRemoteNodeList { NSDictionary *dic = @{@"type":@"2"}; [Remote doJsonAction:1 requestUrl:allNodeListURL parameter:dic delegate:self]; } - (UIButton*)searchBtn { if (!_searchBtn) { _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom]; if (isIOS7) { _searchBtn.frame = CGRectMake(0, 0, (rect_screen.size.width-50)/2, 156/2); }else { _searchBtn.frame = CGRectMake(0, 0, (rect_screen.size.width-50)/2, 60); } [_searchBtn setTitle:@"搜索" forState:UIControlStateNormal]; [_searchBtn addTarget:self action:@selector(pushToSearch:) forControlEvents:UIControlEventTouchUpInside]; if (isIOS7) { [_searchBtn setTitleEdgeInsets:UIEdgeInsetsMake(CGRectGetHeight(_searchBtn.bounds)/2-7+9, CGRectGetWidth(_searchBtn.bounds)/2-15, CGRectGetHeight(_searchBtn.bounds)/2-7-9, CGRectGetWidth(_searchBtn.bounds)/2-15)]; } UIImageView *searchIconImage = [[UIImageView alloc]initWithImage:Image(@"detailPage/searchIcon.png")]; searchIconImage.userInteractionEnabled = YES; [_searchBtn addSubview:searchIconImage]; [searchIconImage makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(_searchBtn.centerX).offset(-35); make.centerY.equalTo(_searchBtn.titleLabel.centerY); make.size.mas_equalTo(CGSizeMake(15, 15)); }]; } _searchBtn.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; [_searchBtn setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal]; [_searchBtn setTitleColor:[UIColor colorWithHexString:TextLightGray] forState:UIControlStateHighlighted]; _searchBtn.titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); return _searchBtn; } - (UIButton*)leakBtn { if (!_leakBtn) { _leakBtn = [UIButton buttonWithType:UIButtonTypeCustom]; if (isIOS7) { _leakBtn.frame = CGRectMake(CGRectGetMaxX(self.searchBtn.frame), 0, (rect_screen.size.width-50)/2, 156/2); }else { _leakBtn.frame = CGRectMake(CGRectGetMaxX(self.searchBtn.frame), 0, (rect_screen.size.width-50)/2, 60); } [_leakBtn setTitle:@"报料" forState:UIControlStateNormal]; [_leakBtn addTarget:self action:@selector(pushToLeak:) forControlEvents:UIControlEventTouchUpInside]; if (isIOS7) { [_leakBtn setTitleEdgeInsets:UIEdgeInsetsMake(CGRectGetHeight(_leakBtn.bounds)/2-7+9, CGRectGetWidth(_leakBtn.bounds)/2-15, CGRectGetHeight(_leakBtn.bounds)/2-7-9, CGRectGetWidth(_leakBtn.bounds)/2-15)]; } UIImageView *leakImageView = [[UIImageView alloc]initWithImage:Image(@"detailPage/leakIcon.png")]; leakImageView.userInteractionEnabled = YES; [_leakBtn addSubview:leakImageView]; [leakImageView makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(_leakBtn.centerX).offset(-35); make.centerY.equalTo(_leakBtn.titleLabel.centerY); make.size.mas_equalTo(CGSizeMake(16, 16)); }]; } _leakBtn.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; [_leakBtn setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal]; [_leakBtn setTitleColor:[UIColor colorWithHexString:TextLightGray] forState:UIControlStateHighlighted]; _leakBtn.titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); return _leakBtn; } - (UIView*)lineView { if (!_lineView) { _lineView = [[UIView alloc]initWithFrame:CGRectMake(50, CGRectGetMaxY(self.searchBtn.frame), 5, CGRectGetHeight(self.view.bounds)-CGRectGetHeight(self.searchBtn.bounds))]; _lineView.autoresizingMask = AutoresizingFull; [_lineView addSubview:self.colorView]; } _lineView.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; return _lineView; } - (UIView*)colorView { if (!_colorView) { _colorView = [[UIView alloc]initWithFrame:CGRectZero]; _colorView.hidden = YES; } return _colorView; } - (UIView*)nodeBtnView { if (!_nodeBtnView) { _nodeBtnView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.searchBtn.frame), 50, CGRectGetHeight(self.view.bounds)-CGRectGetHeight(self.searchBtn.bounds))]; _nodeBtnView.autoresizingMask = AutoresizingFull; } _nodeBtnView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; return _nodeBtnView; } - (LBorderView*)orderLineView { if (!_orderLineView) { _orderLineView = [[LBorderView alloc]initWithFrame:CGRectZero]; _orderLineView.cornerRadius = 0; _orderLineView.borderType = BorderTypeDashed; _orderLineView.borderWidth = 2.0f; _orderLineView.dashPattern = 3.0f; _orderLineView.spacePattern = 3.0f; } _orderLineView.borderColor = [UIColor colorWithHexString:BackGrayGroundColor]; return _orderLineView; } - (UIView*)orderedView { UILabel *titleLabel = (UILabel*)[_orderedView viewWithTag:ORDEREDVIEWTAG]; if (!_orderedView) { _orderedView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.searchBtn.frame), 50, CGRectGetHeight(self.view.bounds)-CGRectGetHeight(self.searchBtn.bounds))]; _orderedView.autoresizingMask = AutoresizingFull; self.orderLineView.hidden = YES; self.orderLineView.frame = CGRectMake(1, CGRectGetHeight(_orderedView.frame)-695/2, CGRectGetWidth(_orderedView.frame)-4, 580/2); [_orderedView addSubview:self.orderLineView]; if (!titleLabel) { titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(35/2, CGRectGetHeight(_orderedView.frame)-160, 16, 150/2)]; titleLabel.tag = ORDEREDVIEWTAG; titleLabel.text = @"拖入订阅"; titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; titleLabel.textAlignment = NSTextAlignmentLeft; titleLabel.lineBreakMode = NSLineBreakByWordWrapping; titleLabel.numberOfLines = 0; [_orderedView addSubview:titleLabel]; UIImageView *goToOrderImageView = [[UIImageView alloc]initWithFrame:CGRectMake(35/2, CGRectGetMinY(titleLabel.frame)-26, 16, 16)]; goToOrderImageView.userInteractionEnabled = YES; goToOrderImageView.image = Image(@"order/goToOrderIcon.png"); [_orderedView addSubview:goToOrderImageView]; /** * bug:5378(栏目导航页:“拖入订阅”上方箭头没显示,详情见图) */ } } titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _orderedView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; titleLabel.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; return _orderedView; } - (nodeInfoController*)nodeInfoController { if (!_nodeInfoController) { _nodeInfoController = [[nodeInfoController alloc]init]; // _nodeInfoController.view.frame = CGRectMake(55, // CGRectGetMaxY(self.searchBarView.bounds), // 430/2, // CGRectGetHeight(self.view.bounds)- CGRectGetHeight(self.searchBarView.bounds)); // _nodeInfoController.view.autoresizingMask = AutoresizingAuto; __weak typeof(self) Self = self; [_nodeInfoController refreshRemoteOrderData:^{ [Self remoteAskOrderData]; }]; [self.view addSubview:_nodeInfoController.view]; [_nodeInfoController.view makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left).offset(55); make.top.equalTo(self.view.top).offset(CGRectGetMaxY(self.searchBtn.bounds)); make.right.equalTo(self.view.right); make.bottom.equalTo(self.view.bottom); }]; } if (!self.longGesture) { self.longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognized:)]; [self.view addGestureRecognizer:self.longGesture]; } return _nodeInfoController; } #pragma mark - data source - (void)setNodeListArray:(NSMutableArray *)list { _nodeListArray = list; if (list.count == 0) { return; } [self.view addSubview:self.lineView]; [self.view addSubview:self.nodeBtnView]; [self.view addSubview:self.orderedView]; [self.view insertSubview:self.orderedView belowSubview:self.nodeBtnView]; [self addChildViewController:self.nodeInfoController]; orderButtonArray = [NSMutableArray array]; if (![TPUserDefault instance].channldataList || [TPUserDefault instance].channldataList.count == 0) { NSDictionary *dic = @{@"type":@"1"}; [Remote doJsonActionWithBlock:0 requestUrl:allNodeListURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { NSArray *nodeArray = responseData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSString *nodeId = obj[@"nodeId"]; NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:obj]; [dic setValue:nodeId forKey:@"nodeId"]; NSString *color = dic[@"color"]; color = [color substringWithRange:NSMakeRange(1, 6)]; color = [NSString stringWithFormat:@"0x%@",color]; [dic setValue:color forKey:@"color"]; [tempArray addObject:dic]; }]; if (tempArray.count == 7) { [TPUserDefault instance].channldataList = tempArray; [self addBtnAfterSetNodeList]; if (list.count != 0) { NSMutableArray *channelList = [TPUserDefault instance].channldataList; NSDictionary *currentDic = channelList[[TPUserDefault instance].currentPageIndex]; __block NSInteger curIndex = -1; [self.nodeListArray enumerateObjectsUsingBlock:^(nodeObjectBO* obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj.nodeId intValue] == [currentDic[@"nodeId"] intValue]) { curIndex = idx; } }]; if (curIndex < 0) { return; } UIButton *orderBtn = (UIButton*)[self.nodeBtnView viewWithTag:ORDERBUTTONTAG+curIndex]; [self orderClickHandler:orderBtn]; } } }else { ShowTextMessage(message); } }]; }else { [self addBtnAfterSetNodeList]; } if (list.count == 0) { return; } NSMutableArray *channelList = [TPUserDefault instance].channldataList; NSDictionary *currentDic = channelList[[TPUserDefault instance].currentPageIndex]; __block NSInteger curIndex = -1; [self.nodeListArray enumerateObjectsUsingBlock:^(nodeObjectBO* obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj.nodeId intValue] == [currentDic[@"nodeId"] intValue]) { curIndex = idx; } }]; if (curIndex < 0) { return; } UIButton *orderBtn = (UIButton*)[self.nodeBtnView viewWithTag:ORDERBUTTONTAG+curIndex]; [self orderClickHandler:orderBtn]; /** * bug:5163(栏目页的频道未与正文的频道同步) */ } - (void)addBtnAfterSetNodeList { NSMutableArray *orderTitleArray = [NSMutableArray array]; NSMutableArray *orderTitleEnglishArray = [NSMutableArray array]; colorArray = [NSMutableArray array]; [self.nodeListArray enumerateObjectsUsingBlock:^(nodeObjectBO* obj, NSUInteger idx, BOOL *stop) { if ([obj.nodeId intValue] == -1) { [orderTitleArray addObject:@"订阅"]; }else{ [orderTitleArray addObject:obj.name]; } [orderTitleEnglishArray addObject:obj.enname]; [colorArray addObject:obj.color]; }]; for (int i=0;i 0) { nodeListDB = [objs objectAtIndex:0]; [[CoreDataManager shareInstance].managedObjectContext deleteObject:nodeListDB]; } NodeListDB *newNodeListDB = nil; newNodeListDB = [NSEntityDescription insertNewObjectForEntityForName:@"NodeListDB" inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext]; newNodeListDB = makeDicToCoreDataModel(responsData, newNodeListDB); newNodeListDB.date = getLocalDate(); [[CoreDataManager shareInstance] saveContext]; NSArray *nodeArray = responsData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { nodeObjectBO *nodeInfo = setJsonDicToDataModel(obj, [nodeObjectBO class]); [tempArray addObject:nodeInfo]; }]; self.nodeListArray = tempArray; } }else if (actionTag == 2){ TPLOG(@"接到订阅数据"); self.orderChildList = [NSMutableArray array]; _currentIndex = 5; /** * bug:5642(【倒退】栏目导航页:如下操作进入栏目导航页,必定闪退) */ if (responsData && responsData[@"nodeList"]) { NSArray *nodeArray = responsData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { nodeObjectBO *nodeInfo = setJsonDicToDataModel(obj, [nodeObjectBO class]); [tempArray addObject:nodeInfo]; }]; [self.orderChildList addObject:@""]; [self.orderChildList addObjectsFromArray:tempArray]; nodeObjectBO *nodeInfo = self.nodeListArray[self.currentIndex]; if (self.orderChildList.count == 0) { nodeInfo.myOrderStatus = @"3"; }else nodeInfo.myOrderStatus = @"1"; self.nodeInfoController.orderNodeBO = nodeInfo; self.nodeInfoController.nodeList = self.orderChildList; if ([[UIApplication sharedApplication]isIgnoringInteractionEvents]) { [[UIApplication sharedApplication]endIgnoringInteractionEvents]; } } }else if (actionTag==100) { ShowMessage(@"订阅成功", YES); [[NSNotificationCenter defaultCenter] postNotificationName:NEEDREFRESHORDER object:nil]; } } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code { if ([code intValue] == 3) { self.orderChildList = [NSMutableArray array]; nodeObjectBO *nodeInfo = self.nodeListArray[self.currentIndex]; if (self.orderChildList.count == 0) { nodeInfo.myOrderStatus = @"3"; }else nodeInfo.myOrderStatus = @"1"; self.nodeInfoController.orderNodeBO = nodeInfo; self.nodeInfoController.nodeList = self.orderChildList; if ([[UIApplication sharedApplication]isIgnoringInteractionEvents]) { [[UIApplication sharedApplication]endIgnoringInteractionEvents]; } return; } ShowTextMessage(message); if (actionTag == 2) { self.orderChildList = [NSMutableArray array]; if ([message isEqualToString:@"您的网络未连接,请设置网络"]) { nodeObjectBO *nodeInfo = self.nodeListArray[4]; nodeInfo.myOrderStatus = @"4"; self.nodeInfoController.orderNodeBO = nodeInfo; self.nodeInfoController.nodeList = self.orderChildList; }else { } if ([[UIApplication sharedApplication]isIgnoringInteractionEvents]) { [[UIApplication sharedApplication]endIgnoringInteractionEvents]; } }else { ShowTextMessage(message); } } /**********************************************************************************/ /**********************************************************************************/ /***************************gesture handler****************************************/ /**********************************************************************************/ /**********************************************************************************/ #pragma mark - long press gesture event - (void)longPressGestureRecognized:(id)sender { UILongPressGestureRecognizer *longPress = (UILongPressGestureRecognizer *)sender; UIGestureRecognizerState state = longPress.state; CGPoint snapLineLocation = [longPress locationInView:self.orderLineView]; if (snapLineLocation.y+CGRectGetWidth(self.nodeInfoController.view.frame)/4> 0 && snapLineLocation.x-CGRectGetWidth(self.nodeInfoController.view.frame)/4< CGRectGetWidth(self.orderLineView.frame)-4) { self.orderLineView.hidden = NO; }else { self.orderLineView.hidden = YES; } CGPoint location = [longPress locationInView:self.view]; // if (location.x <= self.nodeInfoController.view.frame.origin.x) { // return; // } /** * bug:5214(【倒退】在栏目导航页,长按一个栏目拖到左边订阅栏,订阅栏卡主) */ CGPoint collectLoaction = location; collectLoaction.x = collectLoaction.x + self.nodeInfoController.collectionView.contentOffset.x-CGRectGetWidth(self.nodeBtnView.frame); collectLoaction.y = collectLoaction.y + self.nodeInfoController.collectionView.contentOffset.y-CGRectGetHeight(self.searchBtn.frame); NSIndexPath *indexPath = [self.nodeInfoController.collectionView indexPathForItemAtPoint:collectLoaction]; nodeObjectBO *nodeInfo = self.nodeListArray[self.currentIndex]; if ([nodeInfo.nodeId intValue] == -1) { [self myOrderLongPress:longPress indexPath:indexPath]; return; }else if ([nodeInfo.nodeId intValue] == -3) { return; } static UIView *snapshot = nil; static NSIndexPath *sourceIndexPath = nil; switch (state) { case UIGestureRecognizerStateBegan: { if (indexPath) { needGestureOfSideController(NO); [self.view insertSubview:self.orderedView aboveSubview:self.nodeBtnView]; [CoreAnimationEffect animationEaseOut:self.view]; if(!indexPath) { return; } sourceIndexPath = indexPath; nodeInfoCell *cell = (nodeInfoCell*)[self.nodeInfoController.collectionView cellForItemAtIndexPath:indexPath]; [cell setHighlighted:NO]; __block nodeInfoCell *Cell = cell; // Take a snapshot of the selected row using helper method. snapshot = [self customSnapshoFromView:cell]; __block CGPoint center = cell.center; center.y = location.y; center.x = location.x; snapshot.center = center; snapshot.alpha = 0.0; [self.view addSubview:snapshot]; [UIView animateWithDuration:0.2 animations:^{ center.y = location.y; center.x = location.x; snapshot.center = center; snapshot.transform = CGAffineTransformMakeScale(1.1, 1.1); snapshot.alpha = 0.98; } completion:^(BOOL finished) { Cell.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; }]; } break; } case UIGestureRecognizerStateChanged: { CGPoint center = snapshot.center; center.y = location.y; center.x = location.x; snapshot.center = center; break; } default: { //clean up. nodeInfoCell *cell = (nodeInfoCell*)[self.nodeInfoController.collectionView cellForItemAtIndexPath:sourceIndexPath]; __block nodeInfoCell *Cell = cell; __block CGPoint snapShotCenter = cell.center; if (self.orderLineView.hidden) { [UIView animateWithDuration:0.35 animations:^{ snapShotCenter.x = Cell.center.x - self.nodeInfoController.collectionView.contentOffset.x+CGRectGetWidth(self.nodeBtnView.frame); snapShotCenter.y = Cell.center.y - self.nodeInfoController.collectionView.contentOffset.y+CGRectGetHeight(self.searchBtn.frame); snapshot.center = snapShotCenter; snapshot.transform = CGAffineTransformIdentity; snapshot.alpha = 0.0f; Cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [Cell setHighlighted:NO]; } completion:^(BOOL finished) { needGestureOfSideController(YES); [snapshot removeFromSuperview]; snapshot = nil; [self.view insertSubview:self.nodeBtnView aboveSubview:self.orderedView]; [CoreAnimationEffect animationEaseOut:self.view]; }]; }else { [UIView animateWithDuration:0.35 animations:^{ snapShotCenter = self.orderLineView.center; snapShotCenter.y = snapShotCenter.y + 70; snapshot.center = snapShotCenter; snapshot.transform = CGAffineTransformMakeScale(0.1,0.1); snapshot.alpha = 0.0f; // [self.scrollTimer invalidate]; } completion:^(BOOL finished) { Cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [Cell setHighlighted:NO]; needGestureOfSideController(YES); [snapshot removeFromSuperview]; snapshot = nil; if (![TPUserDefault instance].userBO) { loginHomeController *vc = loginHomeController.new; [self.navigationController pushViewController:vc animated:YES]; [self.view insertSubview:self.nodeBtnView aboveSubview:self.orderedView]; [CoreAnimationEffect animationEaseOut:self.view]; return; } nodeObjectBO *nodeBO = Cell.nodeInfoBO; __block BOOL isHaveOrdered = NO; [self.orderChildList enumerateObjectsUsingBlock:^(nodeObjectBO* obj, NSUInteger idx, BOOL *stop) { if (idx > 0) { if ([nodeBO.nodeId doubleValue] == [obj.nodeId doubleValue]) { isHaveOrdered = YES; } } }]; if (isHaveOrdered) { ShowMessage(@"订阅成功", YES); }else { NSDictionary *dic = @{@"n":nodeBO.nodeId,@"oType":@"1"}; [Remote doJsonAction:100 requestUrl:orderNodeURL parameter:dic delegate:self]; } isHaveOrdered = NO; [self.view insertSubview:self.nodeBtnView aboveSubview:self.orderedView]; [CoreAnimationEffect animationEaseOut:self.view]; }]; } sourceIndexPath = nil; break; } } } - (void)myOrderLongPress:(UILongPressGestureRecognizer*)longPress indexPath:(NSIndexPath*)indexPath { //the long press for order page UIGestureRecognizerState state = longPress.state; if (indexPath.row == 0) { return; } nodeInfoCell *cell = (nodeInfoCell*)[self.nodeInfoController.collectionView cellForItemAtIndexPath:indexPath]; switch (state) { case UIGestureRecognizerStateBegan: { if(!indexPath) { return; } // [cell setHighlighted:NO]; [self.nodeInfoController openDeleteMode]; break; } default: { cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [cell setHighlighted:NO]; break; } } } #pragma mark - make snapshot method - (UIView *)customSnapshoFromView:(UIView *)inputView { //The method that 'snapshotViewAfterScreenUpdates' has bugs in iphone 6 and 6+ UIView *snapshot = UIView.new; // if ([inputView respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)]) { //ios 7 snapshot method // snapshot = [inputView snapshotViewAfterScreenUpdates:YES]; // snapshot.layer.masksToBounds = NO; // snapshot.layer.cornerRadius = 0.0; // }else { //...make snapshot avilibile under ios7 // snapshot = [[UIView alloc]initWithFrame:inputView.frame]; // UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, inputView.opaque, 10.0); // [inputView.layer renderInContext:UIGraphicsGetCurrentContext()]; // UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext(); // UIGraphicsEndImageContext(); // UIImageView *imageView = [[UIImageView alloc]initWithImage:viewImage]; // [snapshot addSubview:imageView]; // } snapshot = [[UIView alloc]initWithFrame:inputView.frame]; UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, inputView.opaque, 7.0); [inputView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageView *imageView = [[UIImageView alloc]initWithImage:viewImage]; [snapshot addSubview:imageView]; snapshot.layer.shadowOffset = CGSizeMake(2.0, 2.0); snapshot.layer.shadowRadius = 1.0; snapshot.layer.shadowOpacity = 0.4; snapshot.tag = 7000; return snapshot; } #pragma mark - night mode - (void)refreshAfterOpenNightMode:(NSNotification*)noti { self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.lineView.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; self.nodeBtnView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.orderedView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; UILabel *titleLabel = (UILabel*)[_orderedView viewWithTag:ORDEREDVIEWTAG]; titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; titleLabel.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.leakBtn.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; self.searchBtn.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; [orderButtonArray enumerateObjectsUsingBlock:^(UIButton* button, NSUInteger idx, BOOL *stop) { button.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [button setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal]; UIView *line = [button viewWithTag:1000]; line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; }]; } - (void)dealloc { [[NSNotificationCenter defaultCenter]removeObserver:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end