فهرست منبع

1.修改iOS Apex Mobile KPI双击搜索。

Pen Li 8 سال پیش
والد
کامیت
04d9cb4e22

+ 6 - 0
Apex Mobile/Apex Mobile.xcodeproj/project.pbxproj

@@ -7,6 +7,7 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		420F0CA420901C2E005C4690 /* KPIRepeatTapGestureRecognizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 420F0CA320901C2E005C4690 /* KPIRepeatTapGestureRecognizer.m */; };
 		4235C30320229F7200A99D04 /* Result.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4235C30220229F7200A99D04 /* Result.xib */; };
 		4235C3052022A60A00A99D04 /* ResultCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4235C3042022A60A00A99D04 /* ResultCell.xib */; };
 		4253900E2079B7C700ECF982 /* KPIPieChartCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4253900C2079B7C700ECF982 /* KPIPieChartCell.m */; };
@@ -188,6 +189,8 @@
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
+		420F0CA220901C2E005C4690 /* KPIRepeatTapGestureRecognizer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPIRepeatTapGestureRecognizer.h; sourceTree = "<group>"; };
+		420F0CA320901C2E005C4690 /* KPIRepeatTapGestureRecognizer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KPIRepeatTapGestureRecognizer.m; sourceTree = "<group>"; };
 		4235C30220229F7200A99D04 /* Result.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Result.xib; path = ../../common/customUI/Result.xib; sourceTree = "<group>"; };
 		4235C3042022A60A00A99D04 /* ResultCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ResultCell.xib; path = ../../common/customUI/ResultCell.xib; sourceTree = "<group>"; };
 		4253900B2079B7C700ECF982 /* KPIPieChartCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPIPieChartCell.h; sourceTree = "<group>"; };
@@ -522,6 +525,8 @@
 			isa = PBXGroup;
 			children = (
 				425390152079B7EA00ECF982 /* Cell */,
+				420F0CA220901C2E005C4690 /* KPIRepeatTapGestureRecognizer.h */,
+				420F0CA320901C2E005C4690 /* KPIRepeatTapGestureRecognizer.m */,
 			);
 			name = KPI;
 			sourceTree = "<group>";
@@ -1357,6 +1362,7 @@
 				71E0D1D82022AB7E009A08EB /* ResultViewController.m in Sources */,
 				42BFD2D2207B697800DA9038 /* KPICell.m in Sources */,
 				7157098E2021572600EFE5C5 /* NetworkUtils.m in Sources */,
+				420F0CA420901C2E005C4690 /* KPIRepeatTapGestureRecognizer.m in Sources */,
 				719EF8F118BB839F00EFFF5F /* AppDelegate.m in Sources */,
 				714C39B81922FEE1004F045B /* NewsDetailViewController.m in Sources */,
 				425CF098201EB2B500750E32 /* JLRefreshBasis.m in Sources */,

+ 3 - 1
Apex Mobile/Apex Mobile/AMResultViewController.m

@@ -48,7 +48,9 @@
         fields=[fields stringByAppendingFormat:@"%@,",header_name[i]];
         
     }
-    fields=[fields substringToIndex: fields.length-1];
+    if (fields.length > 0) {
+        fields=[fields substringToIndex: fields.length-1];
+    }
     
     [self.params setValue:fields forKey:@"columns"];
     

+ 40 - 0
Apex Mobile/Apex Mobile/HomeViewController.m

@@ -14,6 +14,7 @@
 #import "RAUtils.h"
 #import "KPICell.h"
 #import "KPITableCell.h"
+#import "AMResultViewController.h"
 
 #define SHIP_CELL_IDENTIFIER @"ShippingStatusCell"
 #define KPI_CELL_IDENTIFIER @"KPITableCell"
@@ -650,6 +651,45 @@ typedef enum {
     return cell;
 }
 
+#pragma mark - KPICell Delegate
+
+- (void)KPICell:(KPICell *)cell repeatClickLegendAtIndex:(NSInteger)index withItem:(NSDictionary *)item {
+    NSLog(@"double clicked %ld",index);
+    /**
+     s_kpi = true;
+     name = kpi name
+     sector = sector title
+     module_name = module_name
+     */
+    NSArray * itemsArr = item[@"arr_val"];
+    NSMutableDictionary* legend = [itemsArr objectAtIndex:index];
+    
+    NSString *kpi_name = [item objectForKey:@"name"];
+    NSString *sector = [legend objectForKey:@"title"];
+    NSString *module_name = [item objectForKey:@"module_name"];
+    if (kpi_name == nil) {
+        kpi_name = @"";
+    }
+    if (sector == nil) {
+        sector = @"";
+    }
+    if (module_name == nil) {
+        module_name = @"";
+    }
+    
+    
+    NSMutableDictionary *params = [@{
+                                     @"s_kpi" : @(YES),
+                                     @"name"  : kpi_name,
+                                     @"sector": sector,
+                                     @"module_name" : module_name
+                                     } mutableCopy];
+    
+    AMResultViewController *resultVC = [[AMResultViewController alloc] initWithNibName:@"Result" bundle:nil];
+    resultVC.params = params;
+    [self.navigationController pushViewController:resultVC animated:YES];
+}
+
 #pragma mark - FlowLayout Delegate
 
 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

+ 3 - 1
Apex Mobile/Apex Mobile/KPICell.h

@@ -8,9 +8,11 @@
 
 #import <UIKit/UIKit.h>
 
+@class KPICell;
 @protocol KPIDelegate <NSObject>
 
-
+@optional
+- (void)KPICell:(KPICell *)cell repeatClickLegendAtIndex:(NSInteger)index withItem:(NSDictionary *)item;
 
 
 @end

+ 70 - 16
Apex Mobile/Apex Mobile/KPICell.m

@@ -11,6 +11,7 @@
 #import "KPIButton.h"
 #import "XYCommon.h"
 #import "KPILegendCell.h"
+#import "KPIRepeatTapGestureRecognizer.h"
 
 #define TAG_INDEX 1024
 
@@ -175,19 +176,6 @@
     [self.itemsContainer addSubview:btn];
 }
 
-- (void)labelClicked:(UIButton *)sender {
-    NSInteger index = sender.tag - TAG_INDEX;
-    NSDictionary *json = _infoDic;
-    NSMutableArray * itemsArr = json[@"arr_val"];
-    NSMutableDictionary* item = [itemsArr objectAtIndex:index];
-    //
-    sender.selected = !sender.selected;
-    [item setObject:@(sender.selected) forKey:@"display"];
-//    [itemsArr replaceObjectAtIndex:index withObject:item];
-//    [self.infoDic setObject:itemsArr forKey:@"arr_val"];
-    [self setInfoDic:self.infoDic];
-}
-
 - (void)awakeFromNib {
     [super awakeFromNib];
     // Initialization code
@@ -262,6 +250,46 @@
 - (IBAction)nextItemBtnClick:(UIButton *)sender {
 
     
+}
+
+- (void)labelClicked:(UIButton *)sender {
+    NSLog(@"labelClicked");
+    NSInteger index = sender.tag - TAG_INDEX;
+    NSDictionary *json = _infoDic;
+    NSMutableArray * itemsArr = json[@"arr_val"];
+    NSMutableDictionary* item = [itemsArr objectAtIndex:index];
+    //
+    sender.selected = !sender.selected;
+    [item setObject:@(sender.selected) forKey:@"display"];
+    //    [itemsArr replaceObjectAtIndex:index withObject:item];
+    //    [self.infoDic setObject:itemsArr forKey:@"arr_val"];
+    [self setInfoDic:self.infoDic];
+}
+
+- (void)legendBtnTaped:(UITapGestureRecognizer *)sender {
+    
+    [self labelClicked:(KPIButton *)sender.view];
+//    [self performSelector:@selector(labelClicked:) withObject:sender afterDelay:0.3];
+//    NSLog(@"tap 1");
+}
+
+- (void)legendBtnRepeatTaped:(UITapGestureRecognizer *)sender {
+//    [NSObject cancelPreviousPerformRequestsWithTarget:sender selector:@selector(labelClicked:) object:sender];
+//    NSLog(@"tap 2");
+
+//    KPIButton *button = (KPIButton *)sender.view;
+//    if (!button.selected) {
+//        return;
+//    }
+    if (self.delegate && [self.delegate respondsToSelector:@selector(KPICell:repeatClickLegendAtIndex:withItem:)]) {
+        NSInteger index = sender.view.tag - TAG_INDEX;
+//        NSDictionary *json = _infoDic;
+//        NSArray * itemsArr = json[@"arr_val"];
+//        NSMutableDictionary* item = [itemsArr objectAtIndex:index];
+        
+        [self.delegate KPICell:self repeatClickLegendAtIndex:index withItem:_infoDic];
+    }
+    
 }
 
 #pragma mark - <选中扇形回调>
@@ -365,8 +393,20 @@
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     
     KPILegendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KPILegndCell" forIndexPath:indexPath];
-    [cell.btn_0 removeTarget:self action:@selector(labelClicked:) forControlEvents:UIControlEventTouchUpInside];
-    [cell.btn_1 removeTarget:self action:@selector(labelClicked:) forControlEvents:UIControlEventTouchUpInside];
+//    [cell.btn_0 removeTarget:self action:@selector(labelClicked:) forControlEvents:UIControlEventTouchUpInside];
+//    [cell.btn_1 removeTarget:self action:@selector(labelClicked:) forControlEvents:UIControlEventTouchUpInside];
+    
+//    [cell.btn_0 removeTarget:self action:@selector(legendBtnTaped:) forControlEvents:UIControlEventTouchDown];
+//    [cell.btn_1 removeTarget:self action:@selector(legendBtnTaped:) forControlEvents:UIControlEventTouchDown];
+//    [cell.btn_0 removeTarget:self action:@selector(legendBtnRepeatTaped:) forControlEvents:UIControlEventTouchDownRepeat];
+//    [cell.btn_1 removeTarget:self action:@selector(legendBtnRepeatTaped:) forControlEvents:UIControlEventTouchDownRepeat];
+    
+    for (UIGestureRecognizer *g in cell.btn_0.gestureRecognizers) {
+        [cell.btn_0 removeGestureRecognizer:g];
+    }
+    for (UIGestureRecognizer *g in cell.btn_1.gestureRecognizers) {
+        [cell.btn_1 removeGestureRecognizer:g];
+    }
     
     NSArray * itemsArr = _infoDic[@"arr_val"];
     
@@ -411,7 +451,21 @@
     btn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
     btn.selected = display;
     btn.tag = TAG_INDEX + index;
-    [btn addTarget:self action:@selector(labelClicked:) forControlEvents:UIControlEventTouchUpInside];
+//    [btn addTarget:self action:@selector(labelClicked:) forControlEvents:UIControlEventTouchUpInside];
+    
+//    [btn addTarget:self action:@selector(legendBtnTaped:) forControlEvents:UIControlEventTouchDown];
+//    [btn addTarget:self action:@selector(legendBtnRepeatTaped:) forControlEvents:UIControlEventTouchDownRepeat];
+    
+    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(legendBtnTaped:)];
+    tap.numberOfTapsRequired = 1;
+    KPIRepeatTapGestureRecognizer *repeatTap = [[KPIRepeatTapGestureRecognizer alloc] initWithTarget:self action:@selector(legendBtnRepeatTaped:)];
+    repeatTap.numberOfTapsRequired = 2;
+    
+    [tap requireGestureRecognizerToFail:repeatTap];
+    
+    [btn addGestureRecognizer:tap];
+    [btn addGestureRecognizer:repeatTap];
+    
 }
 
 #pragma mark - Touch

+ 0 - 6
Apex Mobile/Apex Mobile/KPILegendCell.xib

@@ -20,15 +20,9 @@
                 <subviews>
                     <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Sun-HC-YBP" customClass="KPIButton">
                         <rect key="frame" x="5" y="5" width="179.5" height="34"/>
-                        <connections>
-                            <action selector="btn_0_click:" destination="42d-ZC-jas" eventType="touchUpInside" id="DND-7D-2Ib"/>
-                        </connections>
                     </button>
                     <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="BFw-JA-akt" customClass="KPIButton">
                         <rect key="frame" x="189.5" y="5" width="179.5" height="34"/>
-                        <connections>
-                            <action selector="btn_1_click:" destination="42d-ZC-jas" eventType="touchUpInside" id="xqg-fo-k7M"/>
-                        </connections>
                     </button>
                 </subviews>
                 <constraints>

+ 13 - 0
Apex Mobile/Apex Mobile/KPIRepeatTapGestureRecognizer.h

@@ -0,0 +1,13 @@
+//
+//  KPIRepeatTapGestureRecognizer.h
+//  Apex Mobile
+//
+//  Created by Jack on 2018/4/25.
+//  Copyright © 2018年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface KPIRepeatTapGestureRecognizer : UITapGestureRecognizer
+
+@end

+ 36 - 0
Apex Mobile/Apex Mobile/KPIRepeatTapGestureRecognizer.m

@@ -0,0 +1,36 @@
+//
+//  KPIRepeatTapGestureRecognizer.m
+//  Apex Mobile
+//
+//  Created by Jack on 2018/4/25.
+//  Copyright © 2018年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "KPIRepeatTapGestureRecognizer.h"
+#import <UIKit/UIGestureRecognizerSubclass.h>
+
+@implementation KPIRepeatTapGestureRecognizer
+
+- (instancetype)initWithTarget:(id)target action:(SEL)action {
+    if (self = [super initWithTarget:target action:action]) {
+        
+    }
+    return self;
+}
+
+- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
+    [super touchesEnded:touches withEvent:event];
+    
+    __weak typeof(self) weakSelf = self;
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+        if (weakSelf) {
+            __strong typeof(weakSelf) strongSelf = weakSelf;
+            if (strongSelf.state != UIGestureRecognizerStateRecognized) {
+                strongSelf.state = UIGestureRecognizerStateFailed;
+            }
+        }
+    });
+    
+}
+
+@end