Commit 3afdb34e03532f819f60e911c56caf04d6992405

Authored by yanglingyu
1 parent 2ba6fc2a

启动图,后台控制颜色

CNLiveScioLive/AppDelegate.m
... ... @@ -15,6 +15,9 @@
15 15 #endif
16 16  
17 17 @interface AppDelegate ()<XGPushDelegate>
  18 +{
  19 + UIImageView *imageView;
  20 +}
18 21 @property (nonatomic, assign) BOOL isPush; //区分普通启动还是推送
19 22 @property (nonatomic, copy) NSString *type; //区分首页还是直播 还是id
20 23 @property (nonatomic, assign) BOOL language; //区分消息是中英文语言
... ... @@ -22,7 +25,6 @@
22 25 @end
23 26  
24 27 @implementation AppDelegate
25   -
26 28 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
27 29 // Override point for customization after application launch.
28 30 [self restoreStatusBarOrientation];
... ... @@ -56,7 +58,21 @@
56 58 [self checkAppUpdate];
57 59  
58 60 [self initializeSDKConfiguration];
59   -
  61 + [self requestLanchImage];
  62 + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"lanchImage"];
  63 + if (data.length>0) {
  64 + UIViewController *VC = [[UIViewController alloc] init];
  65 + imageView= [[UIImageView alloc ] initWithFrame :[ UIScreen mainScreen ]. bounds ];
  66 + [imageView setImage:[UIImage imageWithData:data]];
  67 + [VC.view addSubview:imageView];
  68 + self.window.rootViewController = VC;
  69 + [self performSelector:@selector(removeImage) withObject:nil afterDelay:3];
  70 + [self.window makeKeyAndVisible];
  71 + }
  72 + return YES;
  73 +}
  74 +-(void)addRootViewController
  75 +{
60 76 if(IS_CHINESE){
61 77 CNHomeRightViewController *rightVC = [[CNHomeRightViewController alloc]init];
62 78 CNLiveTabBarController *liveTab = [[CNLiveTabBarController alloc] init];
... ... @@ -77,8 +93,48 @@
77 93 self.window.rootViewController = liveTab;
78 94 }
79 95 [self.window makeKeyAndVisible];
80   -
81   - return YES;
  96 +}
  97 +#pragma mark - 请求启动页
  98 +-(void)requestLanchImage
  99 +{
  100 + NSString *urlStr = @"http://app.phonemovie.cnlive.com/gxb/openBanner";
  101 + NSDictionary *parameters = @{@"params":@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"pageUUID\":\"852cde69-ecd8-11e6-b52e-c7d8a7a18cc4\",\"pageType\":\"channelList\"}"};
  102 + [XWHTTPTool GET:urlStr params:parameters success:^(id json) {
  103 + NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json];
  104 + NSURL *url = [NSURL URLWithString:dic[@"data"][@"image"]];
  105 + if ([dic[@"data"][@"grayMode"] isEqualToString:@"true"]) {
  106 + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:ISGRAYMODE];
  107 + }else{
  108 + [[NSUserDefaults standardUserDefaults] setBool:NO forKey:ISGRAYMODE];
  109 + }
  110 + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"lanchImage"];
  111 + if (data.length<=0) {
  112 + [self addRootViewController];
  113 + }
  114 + NSURLSessionConfiguration *configuration = [ NSURLSessionConfiguration defaultSessionConfiguration ];
  115 + AFURLSessionManager *manager = [[ AFURLSessionManager alloc ] initWithSessionConfiguration :configuration];
  116 + NSURLRequest *request = [ NSURLRequest requestWithURL :url];
  117 + NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest :request progress : nil destination :^ NSURL *( NSURL *targetPath, NSURLResponse *response) {
  118 +
  119 + NSURL *documentsDirectoryURL = [[ NSFileManager defaultManager ] URLForDirectory : NSDocumentDirectory inDomain : NSUserDomainMask appropriateForURL : nil create : NO error : nil ];
  120 + return [documentsDirectoryURL URLByAppendingPathComponent :[response suggestedFilename ]];
  121 + } completionHandler :^( NSURLResponse *response, NSURL *filePath, NSError *error) {
  122 + NSLog ( @"File downloaded to: %@" , filePath);
  123 +
  124 + NSData * image = [NSData dataWithContentsOfURL :filePath];
  125 + [[ NSUserDefaults standardUserDefaults ] setObject :image forKey : @"lanchImage"];
  126 +
  127 + }];
  128 + [downloadTask resume ];
  129 +
  130 + } failure:^(NSError *error) {
  131 + [self requestLanchImage];
  132 + }];
  133 +}
  134 +-(void)removeImage{
  135 + [imageView removeFromSuperview];
  136 + imageView = nil;
  137 + [self addRootViewController];
82 138 }
83 139 //语言
84 140 #pragma mark - 语言
... ...
CNLiveScioLive/Pages/Header/SystemMacro.h
... ... @@ -98,6 +98,7 @@ NO)
98 98 #define LoginSuccessful @"LoginSuccessful"
99 99 #define ExitSuccessful @"ExitSuccessful"
100 100 #define GetCodeSuccessful @"GetCodeSuccessful"
  101 +#define ISGRAYMODE @"isGrayMode"
101 102  
102 103 //图片
103 104 #define Image(image) [UIImage imageNamed:image]
... ...
CNLiveScioLive/Pages/Home/CNHomeViewController.m
... ... @@ -93,6 +93,10 @@
93 93 }
94 94 if(controllers.count > 0){
95 95 self.segmentControl.titles = titles;
  96 + if (ininav[@"textColor"]) {
  97 + self.segmentControl.titleSelectColor = [UIColor colorWithHexString:ininav[@"textColor"]];
  98 + [self.segmentControl setBottomViewColor:[UIColor colorWithHexString:ininav[@"textColor"]]];
  99 + }
96 100 self.segmentControl.viewControllers = controllers;
97 101 }
98 102 NSDictionary *dic = @{@"titles":titles};
... ...
CNLiveScioLive/Pages/Tools/ImageGray/UIColor+CNGray.h
... ... @@ -11,7 +11,7 @@
11 11 NS_ASSUME_NONNULL_BEGIN
12 12  
13 13 @interface UIColor (CNGray)
14   -
  14 ++ (instancetype)colorWithHexString:(NSString *)hexStr;
15 15 @end
16 16  
17 17 NS_ASSUME_NONNULL_END
... ...
CNLiveScioLive/Pages/Tools/ImageGray/UIColor+CNGray.m
... ... @@ -20,7 +20,65 @@
20 20 });
21 21 }
22 22 + (UIColor *)cn_colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)a{
23   - CGFloat gray = red*0.299 + green*0.587 + blue*0.114;
24   - return [self cn_colorWithRed:gray green:gray blue:gray alpha:a];
  23 + BOOL isGray = [[NSUserDefaults standardUserDefaults] boolForKey:ISGRAYMODE];
  24 + if (isGray) {
  25 + CGFloat gray = red*0.299 + green*0.587 + blue*0.114;
  26 + return [self cn_colorWithRed:gray green:gray blue:gray alpha:a];
  27 + }
  28 + return [self cn_colorWithRed:red green:green blue:blue alpha:a];
25 29 }
  30 +
  31 +static inline NSUInteger hexStrToInt(NSString *str) {
  32 + uint32_t result = 0;
  33 + sscanf([str UTF8String], "%X", &result);
  34 + return result;
  35 +}
  36 +
  37 +static BOOL hexStrToRGBA(NSString *str,
  38 + CGFloat *r, CGFloat *g, CGFloat *b, CGFloat *a) {
  39 +
  40 +
  41 + str = ({ // Trim blank characters (space and newline) in head and tail.
  42 + NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
  43 + [[str stringByTrimmingCharactersInSet:set] uppercaseString];
  44 +
  45 + });
  46 +
  47 + if ([str hasPrefix:@"#"]) {
  48 + str = [str substringFromIndex:1];
  49 + } else if ([str hasPrefix:@"0X"]) {
  50 + str = [str substringFromIndex:2];
  51 + }
  52 +
  53 + NSUInteger length = [str length];
  54 + // RGB RGBA RRGGBB RRGGBBAA
  55 + if (length != 3 && length != 4 && length != 6 && length != 8) {
  56 + return NO;
  57 + }
  58 +
  59 + //RGB,RGBA,RRGGBB,RRGGBBAA
  60 + if (length < 5) {
  61 + *r = hexStrToInt([str substringWithRange:NSMakeRange(0, 1)]) / 255.0f;
  62 + *g = hexStrToInt([str substringWithRange:NSMakeRange(1, 1)]) / 255.0f;
  63 + *b = hexStrToInt([str substringWithRange:NSMakeRange(2, 1)]) / 255.0f;
  64 + if (length == 4) *a = hexStrToInt([str substringWithRange:NSMakeRange(3, 1)]) / 255.0f;
  65 + else *a = 1;
  66 + } else {
  67 + *r = hexStrToInt([str substringWithRange:NSMakeRange(0, 2)]) / 255.0f;
  68 + *g = hexStrToInt([str substringWithRange:NSMakeRange(2, 2)]) / 255.0f;
  69 + *b = hexStrToInt([str substringWithRange:NSMakeRange(4, 2)]) / 255.0f;
  70 + if (length == 8) *a = hexStrToInt([str substringWithRange:NSMakeRange(6, 2)]) / 255.0f;
  71 + else *a = 1;
  72 + }
  73 + return YES;
  74 +}
  75 +
  76 ++ (instancetype)colorWithHexString:(NSString *)hexStr {
  77 + CGFloat r, g, b, a;
  78 + if (hexStrToRGBA(hexStr, &r, &g, &b, &a)) {
  79 + return [UIColor colorWithRed:r green:g blue:b alpha:a];
  80 + }
  81 + return nil;
  82 +}
  83 +
26 84 @end
... ...
CNLiveScioLive/Pages/Tools/ImageGray/UIImageView+CNGrayImage.m
... ... @@ -24,7 +24,10 @@
24 24 - (void)xmtSwizzledSetImage:(UIImage *)image {
25 25  
26 26 /// 图片使用灰白处理
  27 + BOOL gray = [[NSUserDefaults standardUserDefaults] boolForKey:ISGRAYMODE];
  28 + if (gray) {
27 29 image = [UIImage grayImage:image];
  30 + }
28 31 [self xmtSwizzledSetImage:image];
29 32 }
30 33 @end
... ...
CNLiveScioLive/Pages/Tools/ImageGray/WKWebView+CNGray.m
... ... @@ -20,6 +20,8 @@
20 20 });
21 21 }
22 22 - (instancetype)cn_initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration {
  23 + BOOL gray = [[NSUserDefaults standardUserDefaults] boolForKey:ISGRAYMODE];
  24 + if (gray) {
23 25 // js脚本
24 26 NSString *jScript = @"var filter = '-webkit-filter:grayscale(100%);-moz-filter:grayscale(100%); -ms-filter:grayscale(100%); -o-filter:grayscale(100%) filter:grayscale(100%);';document.getElementsByTagName('html')[0].style.filter = 'grayscale(100%)';meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width, user-scalable=no'); document.getElementsByTagName('head')[0].appendChild(meta);";
25 27 // 注入
... ... @@ -31,6 +33,7 @@
31 33 WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
32 34 wkWebConfig.userContentController = wkUController;
33 35 configuration = wkWebConfig;
  36 + }
34 37 WKWebView *webView = [self cn_initWithFrame:frame configuration:configuration];
35 38 return webView;
36 39 }
... ...