From 5fe7672017dc7cfae39642131c58ea22f251710c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E8=B6=85?= Date: Fri, 2 Jun 2017 10:50:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E7=9A=84URL=E6=94=AF=E6=8C=81=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8Present=E5=87=BA=E6=9D=A5=E7=9A=84VC?= =?UTF-8?q?=E9=87=8CPresent=E9=98=85=E8=AF=BB=E5=99=A8=E5=90=8E=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E8=BF=94=E5=9B=9E=E6=8C=89=E9=92=AE=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LSYReader/Reader/Core/LSYReadUtilites.h | 1 - .../LSYReader/Reader/Core/LSYReadUtilites.m | 31 ------------------- .../LSYReader/Reader/Model/LSYChapterModel.m | 8 +++-- .../LSYReader/Reader/Third/NSString+HTML.h | 2 ++ .../LSYReader/Reader/Third/NSString+HTML.m | 19 ++++++++++++ .../LSYReader/Reader/View/LSYTopMenuView.m | 21 ++++++++++++- 6 files changed, 46 insertions(+), 36 deletions(-) diff --git a/LSYReader/LSYReader/Reader/Core/LSYReadUtilites.h b/LSYReader/LSYReader/Reader/Core/LSYReadUtilites.h index ff00b1b..5ad1d0e 100644 --- a/LSYReader/LSYReader/Reader/Core/LSYReadUtilites.h +++ b/LSYReader/LSYReader/Reader/Core/LSYReadUtilites.h @@ -12,7 +12,6 @@ +(void)separateChapter:(NSMutableArray **)chapters content:(NSString *)content; +(NSString *)encodeWithURL:(NSURL *)url; +(UIButton *)commonButtonSEL:(SEL)sel target:(id)target; -+(UIViewController *)getCurrentVC; +(void)showAlertTitle:(NSString *)title content:(NSString *)string; /** * ePub格式处理 diff --git a/LSYReader/LSYReader/Reader/Core/LSYReadUtilites.m b/LSYReader/LSYReader/Reader/Core/LSYReadUtilites.m index 9b35cd8..94ed1f3 100644 --- a/LSYReader/LSYReader/Reader/Core/LSYReadUtilites.m +++ b/LSYReader/LSYReader/Reader/Core/LSYReadUtilites.m @@ -84,37 +84,6 @@ +(UIButton *)commonButtonSEL:(SEL)sel target:(id)target [button addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside]; return button; } -+(UIViewController *)getCurrentVC -{ - UIViewController *result = nil; - - - UIWindow * window = [[UIApplication sharedApplication] keyWindow]; - if (window.windowLevel != UIWindowLevelNormal) - { - NSArray *windows = [[UIApplication sharedApplication] windows]; - for(UIWindow * tmpWin in windows) - { - if (tmpWin.windowLevel == UIWindowLevelNormal) - { - window = tmpWin; - break; - } - } - } - - - UIView *frontView = [[window subviews] objectAtIndex:0]; - id nextResponder = [frontView nextResponder]; - - - if ([nextResponder isKindOfClass:[UIViewController class]]) - result = nextResponder; - else - result = window.rootViewController; - - return result; -} +(void)showAlertTitle:(NSString *)title content:(NSString *)string { #pragma clang diagnostic push diff --git a/LSYReader/LSYReader/Reader/Model/LSYChapterModel.m b/LSYReader/LSYReader/Reader/Model/LSYChapterModel.m index 55b195b..0d3eab4 100644 --- a/LSYReader/LSYReader/Reader/Model/LSYChapterModel.m +++ b/LSYReader/LSYReader/Reader/Model/LSYChapterModel.m @@ -26,12 +26,13 @@ - (instancetype)init } +(id)chapterWithEpub:(NSString *)chapterpath title:(NSString *)title imagePath:(NSString *)path { + NSString * tmp=[chapterpath URLDecodedString]; LSYChapterModel *model = [[LSYChapterModel alloc] init]; model.title = title; model.epubImagePath = path; model.type = ReaderEpub; - model.chapterpath = chapterpath; - NSString* html = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:chapterpath]] encoding:NSUTF8StringEncoding]; + model.chapterpath = tmp; + NSString* html = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:tmp]] encoding:NSUTF8StringEncoding]; model.html = html; model.content = [html stringByConvertingHTMLToPlainText]; [model parserEpubToDictionary]; @@ -49,7 +50,8 @@ -(void)parserEpubToDictionary if ([scanner scanString:@"" intoString:NULL]) { NSString *img; [scanner scanUpToString:@"" intoString:&img]; - NSString *imageString = [self.epubImagePath stringByAppendingPathComponent:img]; + NSString *temp = [self.epubImagePath stringByAppendingPathComponent:img]; + NSString * imageString=[temp URLDecodedString]; UIImage *image = [UIImage imageWithContentsOfFile:imageString]; CGSize size = CGSizeMake((ScreenSize.width-LeftSpacing-RightSpacing), (ScreenSize.width-LeftSpacing-RightSpacing)/(ScreenSize.height-TopSpacing-BottomSpacing)*image.size.width); if (size.height>(ScreenSize.height-TopSpacing-BottomSpacing-20)) { diff --git a/LSYReader/LSYReader/Reader/Third/NSString+HTML.h b/LSYReader/LSYReader/Reader/Third/NSString+HTML.h index 57867d0..4e2763e 100755 --- a/LSYReader/LSYReader/Reader/Third/NSString+HTML.h +++ b/LSYReader/LSYReader/Reader/Third/NSString+HTML.h @@ -43,4 +43,6 @@ // DEPRECIATED - Please use NSString stringByConvertingHTMLToPlainText - (NSString *)stringByStrippingTags; +-(NSString *)URLEncodedString; +-(NSString *)URLDecodedString; @end diff --git a/LSYReader/LSYReader/Reader/Third/NSString+HTML.m b/LSYReader/LSYReader/Reader/Third/NSString+HTML.m index d86df30..0c6d210 100755 --- a/LSYReader/LSYReader/Reader/Third/NSString+HTML.m +++ b/LSYReader/LSYReader/Reader/Third/NSString+HTML.m @@ -361,4 +361,23 @@ - (NSString *)stringByStrippingTags { } +- (NSString *)URLEncodedString +{ + NSString *encodedString = (NSString *) + CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, + (CFStringRef)self, + (CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]", + NULL, + kCFStringEncodingUTF8)); + return encodedString; +} + +-(NSString *)URLDecodedString +{ + NSString *decodedString=(__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (__bridge CFStringRef)self, CFSTR(""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)); + + return decodedString; +} + + @end diff --git a/LSYReader/LSYReader/Reader/View/LSYTopMenuView.m b/LSYReader/LSYReader/Reader/View/LSYTopMenuView.m index b1c2f59..8680f6e 100644 --- a/LSYReader/LSYReader/Reader/View/LSYTopMenuView.m +++ b/LSYReader/LSYReader/Reader/View/LSYTopMenuView.m @@ -61,7 +61,26 @@ -(void)moreOption } -(void)backView { - [[LSYReadUtilites getCurrentVC] dismissViewControllerAnimated:YES completion:nil]; + [[self topViewController] dismissViewControllerAnimated:YES completion:nil]; +} +- (UIViewController *)topViewController { + UIViewController *resultVC; + resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]]; + while (resultVC.presentedViewController) { + resultVC = [self _topViewController:resultVC.presentedViewController]; + } + return resultVC; +} + +- (UIViewController *)_topViewController:(UIViewController *)vc { + if ([vc isKindOfClass:[UINavigationController class]]) { + return [self _topViewController:[(UINavigationController *)vc topViewController]]; + }else if ([vc isKindOfClass:[UITabBarController class]]) { + return [self _topViewController:[(UITabBarController *)vc selectedViewController]]; + } else { + return vc; + } + return nil; } -(void)layoutSubviews {