├── .gitignore ├── AutolayoutDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── AutolayoutDemo.xccheckout │ └── xcuserdata │ │ ├── dengbin.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ ├── song.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── songwentong.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── dengbin.xcuserdatad │ └── xcschemes │ │ ├── AutolayoutDemo.xcscheme │ │ └── xcschememanagement.plist │ ├── song.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ ├── AutolayoutDemo.xcscheme │ │ └── xcschememanagement.plist │ └── songwentong.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── AutolayoutDemo.xcscheme │ └── xcschememanagement.plist ├── AutolayoutDemo ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── File ├── FirstViewController.h ├── FirstViewController.m ├── Images.xcassets │ ├── AppIcon.appiconset │ │ ├── AppIcon29x29@2x.png │ │ ├── AppIcon29x29@3x.png │ │ ├── AppIcon60x60@3x.png │ │ ├── Contents.json │ │ ├── icon175x175 3-1.png │ │ ├── icon175x175 3-2.png │ │ └── icon175x175 3.png │ ├── LaunchImage.launchimage │ │ ├── Contents.json │ │ ├── LaunchImage-700-568h@2x-1.png │ │ ├── LaunchImage-700-568h@2x.png │ │ ├── LaunchImage-800-667h@2x.png │ │ ├── LaunchImage-800-Portrait-736h@3x.png │ │ ├── LaunchImage.png │ │ ├── LaunchImage@2x-1.png │ │ └── LaunchImage@2x.png │ ├── comment_profile_mars.imageset │ │ ├── Contents.json │ │ └── comment_profile_mars@2x.png │ ├── comment_support.imageset │ │ ├── Contents.json │ │ └── comment_support@2x.png │ ├── comment_support_highlighted.imageset │ │ ├── Contents.json │ │ └── comment_support_highlighted@2x.png │ ├── contentview_commentbacky.imageset │ │ ├── Contents.json │ │ └── contentview_commentbacky@2x.png │ ├── contentview_commentbacky_selected.imageset │ │ ├── Contents.json │ │ └── contentview_commentbacky_selected@2x.png │ ├── first.imageset │ │ ├── Contents.json │ │ └── first.pdf │ └── second.imageset │ │ ├── Contents.json │ │ └── second.pdf ├── Info.plist ├── Library │ ├── GBVersionTracking │ │ ├── GBVersionTracking.h │ │ └── GBVersionTracking.m │ ├── UICKeyChainStore │ │ ├── UICKeyChainStore.h │ │ └── UICKeyChainStore.m │ ├── UIKit+WTRequestCenter │ │ ├── UIAlertView+WTRequestCenter.h │ │ ├── UIAlertView+WTRequestCenter.m │ │ ├── UIApplication+WTRequestCenter.h │ │ ├── UIApplication+WTRequestCenter.m │ │ ├── UIButton+WTRequestCenter.h │ │ ├── UIButton+WTRequestCenter.m │ │ ├── UIColor+WTRequestCenter.h │ │ ├── UIColor+WTRequestCenter.m │ │ ├── UIDevice+WTRequestCenter.h │ │ ├── UIDevice+WTRequestCenter.m │ │ ├── UIImage+WTRequestCenter.h │ │ ├── UIImage+WTRequestCenter.m │ │ ├── UIImageView+WTRequestCenter.h │ │ ├── UIImageView+WTRequestCenter.m │ │ ├── UIKit+WTRequestCenter.h │ │ ├── UIScreen+WTRequestCenter.h │ │ ├── UIScreen+WTRequestCenter.m │ │ ├── UIWebView+WTRequestCenter.h │ │ ├── UIWebView+WTRequestCenter.m │ │ ├── WTDataSaver.h │ │ ├── WTDataSaver.m │ │ ├── WTImageViewer.h │ │ ├── WTImageViewer.m │ │ ├── WTNetworkActivityIndicatorManager.h │ │ ├── WTNetworkActivityIndicatorManager.m │ │ └── WTRequestCenterMacro.h │ └── WTRequestCenter │ │ ├── WTNetWork.h │ │ ├── WTRequestCenter.h │ │ ├── WTRequestCenter.m │ │ ├── WTURLRequestOperation.h │ │ ├── WTURLRequestOperation.m │ │ ├── WTURLRequestSerialization.h │ │ ├── WTURLRequestSerialization.m │ │ ├── WTURLSessionManager.h │ │ └── WTURLSessionManager.m ├── Model │ ├── NewsCenter.h │ └── NewsCenter.m ├── Resource │ ├── Data │ │ └── topic_news.json │ └── Font │ │ ├── DS-DIGI.TTF │ │ ├── DS-DIGIB.TTF │ │ ├── StencilStd.ttf │ │ └── lijinheiW8.TTF ├── SecondViewController.h ├── SecondViewController.m ├── View and ViewControllers │ ├── AtlasViewController.h │ ├── AtlasViewController.m │ ├── AtlasViewController.xib │ ├── CommentCell.h │ ├── CommentCell.m │ ├── CommentCell.xib │ ├── CommentVC.h │ ├── CommentVC.m │ ├── CommentVC.xib │ ├── DBPictureVC.h │ ├── DBPictureVC.m │ ├── NewsCenter.h │ ├── NewsCenter.m │ ├── NewsDetailViewController.h │ ├── NewsDetailViewController.m │ ├── NewsHeadTableViewCell.h │ ├── NewsHeadTableViewCell.m │ ├── NewsHeadTableViewCell.xib │ ├── NewsImageCollectionViewCell.h │ ├── NewsImageCollectionViewCell.m │ ├── NewsImageCollectionViewCell.xib │ ├── NewsTableView.h │ ├── NewsTableView.m │ ├── NewsTableViewCell.h │ ├── NewsTableViewCell.m │ ├── NewsTableViewCell.xib │ ├── NewsTitleCell.h │ ├── NewsTitleCell.m │ ├── NormalNewDetailVC.h │ ├── NormalNewDetailVC.m │ └── NormalNewDetailVC.xib └── main.m ├── AutolayoutDemoTests ├── AutolayoutDemoTests.m └── Info.plist ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/project.xcworkspace/xcshareddata/AutolayoutDemo.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | D100C71E-FD36-46F6-9020-979894B9314D 9 | IDESourceControlProjectName 10 | AutolayoutDemo 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 0E4DB37D1F4C7EF16704372A8A1B757D8FCB725C 14 | https://github.com/swtlovewtt/EasyNews.git 15 | 16 | IDESourceControlProjectPath 17 | AutolayoutDemo.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 0E4DB37D1F4C7EF16704372A8A1B757D8FCB725C 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/swtlovewtt/EasyNews.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 0E4DB37D1F4C7EF16704372A8A1B757D8FCB725C 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 0E4DB37D1F4C7EF16704372A8A1B757D8FCB725C 36 | IDESourceControlWCCName 37 | EasyNews 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/project.xcworkspace/xcuserdata/dengbin.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo.xcodeproj/project.xcworkspace/xcuserdata/dengbin.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/project.xcworkspace/xcuserdata/song.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo.xcodeproj/project.xcworkspace/xcuserdata/song.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/project.xcworkspace/xcuserdata/songwentong.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo.xcodeproj/project.xcworkspace/xcuserdata/songwentong.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/xcuserdata/dengbin.xcuserdatad/xcschemes/AutolayoutDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/xcuserdata/dengbin.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AutolayoutDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E42AB9561A5680240004E1E8 16 | 17 | primary 18 | 19 | 20 | E42AB9721A5680240004E1E8 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/xcuserdata/song.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/xcuserdata/song.xcuserdatad/xcschemes/AutolayoutDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 89 | 90 | 91 | 92 | 98 | 99 | 105 | 106 | 107 | 108 | 110 | 111 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/xcuserdata/song.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AutolayoutDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E42AB9561A5680240004E1E8 16 | 17 | primary 18 | 19 | 20 | E42AB9721A5680240004E1E8 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/xcuserdata/songwentong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/xcuserdata/songwentong.xcuserdatad/xcschemes/AutolayoutDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 89 | 90 | 91 | 92 | 98 | 99 | 105 | 106 | 107 | 108 | 110 | 111 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /AutolayoutDemo.xcodeproj/xcuserdata/songwentong.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AutolayoutDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E42AB9561A5680240004E1E8 16 | 17 | primary 18 | 19 | 20 | E42AB9721A5680240004E1E8 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /AutolayoutDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // https://github.com/ChinaiOSDeveloper/EasyNews 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /AutolayoutDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | //#import "WTNetWork.h" 11 | #import "UIKit+WTRequestCenter.h" 12 | #import "GBVersionTracking.h" 13 | @interface AppDelegate () 14 | 15 | @end 16 | 17 | @implementation AppDelegate 18 | 19 | 20 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 21 | // Override point for customization after application launch. 22 | 23 | 24 | // 网络指示器 25 | [WTNetworkActivityIndicatorManager sharedManager].enabled = YES; 26 | 27 | // 启动记录 28 | [GBVersionTracking track]; 29 | 30 | return YES; 31 | } 32 | 33 | - (void)applicationWillResignActive:(UIApplication *)application { 34 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 35 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 36 | } 37 | 38 | - (void)applicationDidEnterBackground:(UIApplication *)application { 39 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 40 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 41 | } 42 | 43 | - (void)applicationWillEnterForeground:(UIApplication *)application { 44 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 45 | } 46 | 47 | - (void)applicationDidBecomeActive:(UIApplication *)application { 48 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 49 | } 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /AutolayoutDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AutolayoutDemo/FirstViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FirstViewController.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FirstViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/AppIcon.appiconset/AppIcon29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/AppIcon.appiconset/AppIcon29x29@2x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/AppIcon.appiconset/AppIcon29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/AppIcon.appiconset/AppIcon29x29@3x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/AppIcon.appiconset/AppIcon60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/AppIcon.appiconset/AppIcon60x60@3x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "29x29", 5 | "idiom" : "iphone", 6 | "filename" : "AppIcon29x29@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "29x29", 11 | "idiom" : "iphone", 12 | "filename" : "AppIcon29x29@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "40x40", 17 | "idiom" : "iphone", 18 | "filename" : "icon175x175 3-2.png", 19 | "scale" : "2x" 20 | }, 21 | { 22 | "size" : "40x40", 23 | "idiom" : "iphone", 24 | "filename" : "icon175x175 3-1.png", 25 | "scale" : "3x" 26 | }, 27 | { 28 | "size" : "60x60", 29 | "idiom" : "iphone", 30 | "filename" : "icon175x175 3.png", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "size" : "60x60", 35 | "idiom" : "iphone", 36 | "filename" : "AppIcon60x60@3x.png", 37 | "scale" : "3x" 38 | } 39 | ], 40 | "info" : { 41 | "version" : 1, 42 | "author" : "xcode" 43 | } 44 | } -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/AppIcon.appiconset/icon175x175 3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/AppIcon.appiconset/icon175x175 3-1.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/AppIcon.appiconset/icon175x175 3-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/AppIcon.appiconset/icon175x175 3-2.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/AppIcon.appiconset/icon175x175 3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/AppIcon.appiconset/icon175x175 3.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "extent" : "full-screen", 5 | "idiom" : "iphone", 6 | "subtype" : "736h", 7 | "filename" : "LaunchImage-800-Portrait-736h@3x.png", 8 | "minimum-system-version" : "8.0", 9 | "orientation" : "portrait", 10 | "scale" : "3x" 11 | }, 12 | { 13 | "orientation" : "landscape", 14 | "idiom" : "iphone", 15 | "extent" : "full-screen", 16 | "minimum-system-version" : "8.0", 17 | "subtype" : "736h", 18 | "scale" : "3x" 19 | }, 20 | { 21 | "extent" : "full-screen", 22 | "idiom" : "iphone", 23 | "subtype" : "667h", 24 | "filename" : "LaunchImage-800-667h@2x.png", 25 | "minimum-system-version" : "8.0", 26 | "orientation" : "portrait", 27 | "scale" : "2x" 28 | }, 29 | { 30 | "orientation" : "portrait", 31 | "idiom" : "iphone", 32 | "extent" : "full-screen", 33 | "minimum-system-version" : "7.0", 34 | "filename" : "LaunchImage@2x-1.png", 35 | "scale" : "2x" 36 | }, 37 | { 38 | "extent" : "full-screen", 39 | "idiom" : "iphone", 40 | "subtype" : "retina4", 41 | "filename" : "LaunchImage-700-568h@2x-1.png", 42 | "minimum-system-version" : "7.0", 43 | "orientation" : "portrait", 44 | "scale" : "2x" 45 | }, 46 | { 47 | "orientation" : "portrait", 48 | "idiom" : "ipad", 49 | "extent" : "full-screen", 50 | "minimum-system-version" : "7.0", 51 | "scale" : "1x" 52 | }, 53 | { 54 | "orientation" : "landscape", 55 | "idiom" : "ipad", 56 | "extent" : "full-screen", 57 | "minimum-system-version" : "7.0", 58 | "scale" : "1x" 59 | }, 60 | { 61 | "orientation" : "portrait", 62 | "idiom" : "ipad", 63 | "extent" : "full-screen", 64 | "minimum-system-version" : "7.0", 65 | "scale" : "2x" 66 | }, 67 | { 68 | "orientation" : "landscape", 69 | "idiom" : "ipad", 70 | "extent" : "full-screen", 71 | "minimum-system-version" : "7.0", 72 | "scale" : "2x" 73 | }, 74 | { 75 | "orientation" : "portrait", 76 | "idiom" : "iphone", 77 | "extent" : "full-screen", 78 | "filename" : "LaunchImage.png", 79 | "scale" : "1x" 80 | }, 81 | { 82 | "orientation" : "portrait", 83 | "idiom" : "iphone", 84 | "extent" : "full-screen", 85 | "filename" : "LaunchImage@2x.png", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "orientation" : "portrait", 90 | "idiom" : "iphone", 91 | "extent" : "full-screen", 92 | "filename" : "LaunchImage-700-568h@2x.png", 93 | "subtype" : "retina4", 94 | "scale" : "2x" 95 | }, 96 | { 97 | "orientation" : "portrait", 98 | "idiom" : "ipad", 99 | "extent" : "to-status-bar", 100 | "scale" : "1x" 101 | }, 102 | { 103 | "orientation" : "portrait", 104 | "idiom" : "ipad", 105 | "extent" : "full-screen", 106 | "scale" : "1x" 107 | }, 108 | { 109 | "orientation" : "landscape", 110 | "idiom" : "ipad", 111 | "extent" : "to-status-bar", 112 | "scale" : "1x" 113 | }, 114 | { 115 | "orientation" : "landscape", 116 | "idiom" : "ipad", 117 | "extent" : "full-screen", 118 | "scale" : "1x" 119 | }, 120 | { 121 | "orientation" : "portrait", 122 | "idiom" : "ipad", 123 | "extent" : "to-status-bar", 124 | "scale" : "2x" 125 | }, 126 | { 127 | "orientation" : "portrait", 128 | "idiom" : "ipad", 129 | "extent" : "full-screen", 130 | "scale" : "2x" 131 | }, 132 | { 133 | "orientation" : "landscape", 134 | "idiom" : "ipad", 135 | "extent" : "to-status-bar", 136 | "scale" : "2x" 137 | }, 138 | { 139 | "orientation" : "landscape", 140 | "idiom" : "ipad", 141 | "extent" : "full-screen", 142 | "scale" : "2x" 143 | } 144 | ], 145 | "info" : { 146 | "version" : 1, 147 | "author" : "xcode" 148 | } 149 | } -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage-700-568h@2x-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage-700-568h@2x-1.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage-700-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage-700-568h@2x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage-800-667h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage-800-667h@2x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage-800-Portrait-736h@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage-800-Portrait-736h@3x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage@2x-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage@2x-1.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/LaunchImage.launchimage/LaunchImage@2x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/comment_profile_mars.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "comment_profile_mars@2x.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/comment_profile_mars.imageset/comment_profile_mars@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/comment_profile_mars.imageset/comment_profile_mars@2x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/comment_support.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "comment_support@2x.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/comment_support.imageset/comment_support@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/comment_support.imageset/comment_support@2x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/comment_support_highlighted.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "comment_support_highlighted@2x.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/comment_support_highlighted.imageset/comment_support_highlighted@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/comment_support_highlighted.imageset/comment_support_highlighted@2x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/contentview_commentbacky.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "contentview_commentbacky@2x.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/contentview_commentbacky.imageset/contentview_commentbacky@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/contentview_commentbacky.imageset/contentview_commentbacky@2x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/contentview_commentbacky_selected.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "contentview_commentbacky_selected@2x.png" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/contentview_commentbacky_selected.imageset/contentview_commentbacky_selected@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/contentview_commentbacky_selected.imageset/contentview_commentbacky_selected@2x.png -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/first.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "first.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/first.imageset/first.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/first.imageset/first.pdf -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/second.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "second.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /AutolayoutDemo/Images.xcassets/second.imageset/second.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Images.xcassets/second.imageset/second.pdf -------------------------------------------------------------------------------- /AutolayoutDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | myCom.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | 网易新闻 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UIStatusBarStyle 32 | UIStatusBarStyleDefault 33 | UIStatusBarTintParameters 34 | 35 | UINavigationBar 36 | 37 | Style 38 | UIBarStyleDefault 39 | Translucent 40 | 41 | 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | 47 | UIViewControllerBasedStatusBarAppearance 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/GBVersionTracking/GBVersionTracking.h: -------------------------------------------------------------------------------- 1 | // 2 | // GBVersionTracking.h 3 | // GBVersionTracking 4 | // 5 | // Created by Luka Mirosevic on 28/01/2013. 6 | // Copyright (c) 2013 Goonbee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^GBVersionTrackingHandlerBlock)(void); 12 | 13 | @interface GBVersionTracking : NSObject 14 | 15 | //Call this in application:didFinishLaunching:withOptions: 16 | +(void)track; 17 | 18 | //First time ever the app is launched, irrespective of version? 19 | +(BOOL)isFirstLaunchEver; 20 | 21 | //First time this particular version is being launched? 22 | +(BOOL)isFirstLaunchForVersion; 23 | 24 | //First time this particular build is being launched? 25 | +(BOOL)isFirstLaunchForBuild; 26 | 27 | //First time a specific version is being launched? 28 | +(BOOL)isFirstLaunchForVersion:(NSString *)version; 29 | 30 | //First time a specific build is being launched? 31 | +(BOOL)isFirstLaunchForBuild:(NSString *)build; 32 | 33 | //Call a block once a particular verison is launched for the firs time 34 | +(void)callBlockOnFirstLaunchOfVersion:(NSString *)version block:(GBVersionTrackingHandlerBlock)block; 35 | 36 | //Call a block once a particular build is launched for the first time 37 | +(void)callBlockOnFirstLaunchOfBuild:(NSString *)build block:(GBVersionTrackingHandlerBlock)block; 38 | 39 | +(NSString *)currentVersion; 40 | +(NSString *)previousVersion; 41 | +(NSArray *)versionHistory; 42 | 43 | +(NSString *)currentBuild; 44 | +(NSString *)previousBuild; 45 | +(NSArray *)buildHistory; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/GBVersionTracking/GBVersionTracking.m: -------------------------------------------------------------------------------- 1 | // 2 | // GBVersionTracking.m 3 | // GBVersionTracking 4 | // 5 | // Created by Luka Mirosevic on 28/01/2013. 6 | // Copyright (c) 2013 Goonbee. All rights reserved. 7 | // 8 | 9 | #import "GBVersionTracking.h" 10 | 11 | // Allows making public interface a little simpler by wrapping all singleton instance methods inside class methods 12 | #define _controller [GBVersionTracking sharedController] 13 | 14 | static NSString * const kGBVersionTrail = @"kGBVersionTrail"; 15 | static NSString * const kGBVersion = @"kGBVersion"; 16 | static NSString * const kGBBuild = @"kGBBuild"; 17 | 18 | 19 | @interface GBVersionTracking () 20 | 21 | @property (strong, nonatomic) NSDictionary *versionTrail; 22 | @property (assign, nonatomic) BOOL isFirstLaunchEver; 23 | @property (assign, nonatomic) BOOL isFirstLaunchForVersion; 24 | @property (assign, nonatomic) BOOL isFirstLaunchForBuild; 25 | 26 | @end 27 | 28 | 29 | @implementation GBVersionTracking 30 | 31 | #pragma mark - Storage 32 | 33 | +(GBVersionTracking *)sharedController { 34 | static GBVersionTracking *sharedController; 35 | @synchronized(self) { 36 | if (!sharedController) { 37 | sharedController = [GBVersionTracking new]; 38 | } 39 | return sharedController; 40 | } 41 | } 42 | 43 | #pragma mark - Public API 44 | 45 | //store a version crumb tail in NSUserDefaults 46 | +(void)track { 47 | BOOL needsSync = NO; 48 | 49 | //load history 50 | NSDictionary *oldVersionTrail = [[NSUserDefaults standardUserDefaults] objectForKey:kGBVersionTrail]; 51 | 52 | //check if its the first ever launch 53 | if (oldVersionTrail == nil) { 54 | _controller.isFirstLaunchEver = YES; 55 | 56 | _controller.versionTrail = @{kGBVersion: [NSMutableArray new], kGBBuild: [NSMutableArray new]}; 57 | } 58 | else { 59 | _controller.isFirstLaunchEver = NO; 60 | 61 | //read the old datastructure out but make a deeply mutable copy of it first 62 | _controller.versionTrail = @{kGBVersion: [oldVersionTrail[kGBVersion] mutableCopy], kGBBuild: [oldVersionTrail[kGBBuild] mutableCopy]}; 63 | 64 | needsSync = YES; 65 | } 66 | 67 | //check if this version was previously launched 68 | if ([_controller.versionTrail[kGBVersion] containsObject:[self currentVersion]]) { 69 | _controller.isFirstLaunchForVersion = NO; 70 | } 71 | else { 72 | _controller.isFirstLaunchForVersion = YES; 73 | 74 | [_controller.versionTrail[kGBVersion] addObject:[self currentVersion]]; 75 | 76 | needsSync = YES; 77 | } 78 | 79 | //check if this build was previously launched 80 | if ([_controller.versionTrail[kGBBuild] containsObject:[self currentBuild]]) { 81 | _controller.isFirstLaunchForBuild = NO; 82 | } 83 | else { 84 | _controller.isFirstLaunchForBuild = YES; 85 | 86 | [_controller.versionTrail[kGBBuild] addObject:[self currentBuild]]; 87 | 88 | needsSync = YES; 89 | } 90 | 91 | //store the new version stuff 92 | if (needsSync) { 93 | [[NSUserDefaults standardUserDefaults] setObject:_controller.versionTrail forKey:kGBVersionTrail]; 94 | [[NSUserDefaults standardUserDefaults] synchronize]; 95 | } 96 | } 97 | 98 | +(BOOL)isFirstLaunchEver { 99 | return _controller.isFirstLaunchEver; 100 | } 101 | 102 | +(BOOL)isFirstLaunchForVersion { 103 | return _controller.isFirstLaunchForVersion; 104 | } 105 | 106 | +(BOOL)isFirstLaunchForBuild { 107 | return _controller.isFirstLaunchForBuild; 108 | } 109 | 110 | +(BOOL)isFirstLaunchForVersion:(NSString *)version { 111 | if ([[self currentVersion] isEqualToString:version]) { 112 | return [self isFirstLaunchForVersion]; 113 | } 114 | else { 115 | return NO; 116 | } 117 | } 118 | 119 | +(BOOL)isFirstLaunchForBuild:(NSString *)build { 120 | if ([[self currentBuild] isEqualToString:build]) { 121 | return [self isFirstLaunchForBuild]; 122 | } 123 | else { 124 | return NO; 125 | } 126 | } 127 | 128 | +(void)callBlockOnFirstLaunchOfVersion:(NSString *)version block:(GBVersionTrackingHandlerBlock)block { 129 | if ([self isFirstLaunchForVersion:version] && block) { 130 | block(); 131 | } 132 | } 133 | 134 | +(void)callBlockOnFirstLaunchOfBuild:(NSString *)build block:(GBVersionTrackingHandlerBlock)block { 135 | if ([self isFirstLaunchForBuild:build] && block) { 136 | block(); 137 | } 138 | } 139 | 140 | #pragma mark - Version 141 | 142 | +(NSString *)currentVersion { 143 | return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; 144 | } 145 | 146 | +(NSString *)previousVersion { 147 | NSUInteger count = [_controller.versionTrail[kGBVersion] count]; 148 | if (count >= 2) { 149 | return _controller.versionTrail[kGBVersion][count-2]; 150 | } 151 | else return nil; 152 | } 153 | 154 | +(NSArray *)versionHistory { 155 | return _controller.versionTrail[kGBVersion]; 156 | } 157 | 158 | #pragma mark - Build 159 | 160 | +(NSString *)currentBuild { 161 | return [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; 162 | } 163 | 164 | +(NSString *)previousBuild { 165 | NSUInteger count = [_controller.versionTrail[kGBBuild] count]; 166 | if (count >= 2) { 167 | return _controller.versionTrail[kGBBuild][count-2]; 168 | } 169 | else return nil; 170 | } 171 | 172 | +(NSArray *)buildHistory { 173 | return _controller.versionTrail[kGBBuild]; 174 | } 175 | 176 | @end 177 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UICKeyChainStore/UICKeyChainStore.h: -------------------------------------------------------------------------------- 1 | // 2 | // UICKeyChainStore.h 3 | // UICKeyChainStore 4 | // 5 | // Created by Kishikawa Katsumi on 11/11/20. 6 | // Copyright (c) 2011 Kishikawa Katsumi. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UICKeyChainStore : NSObject 12 | 13 | @property (nonatomic, readonly) NSString *service; 14 | @property (nonatomic, readonly) NSString *accessGroup; 15 | 16 | + (NSString *)stringForKey:(NSString *)key; 17 | + (NSString *)stringForKey:(NSString *)key service:(NSString *)service; 18 | + (NSString *)stringForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup; 19 | + (BOOL)setString:(NSString *)value forKey:(NSString *)key; 20 | + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service; 21 | + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup; 22 | 23 | + (NSData *)dataForKey:(NSString *)key; 24 | + (NSData *)dataForKey:(NSString *)key service:(NSString *)service; 25 | + (NSData *)dataForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup; 26 | + (BOOL)setData:(NSData *)data forKey:(NSString *)key; 27 | + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service; 28 | + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup; 29 | 30 | + (BOOL)removeItemForKey:(NSString *)key; 31 | + (BOOL)removeItemForKey:(NSString *)key service:(NSString *)service; 32 | + (BOOL)removeItemForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup; 33 | + (BOOL)removeAllItems; 34 | + (BOOL)removeAllItemsForService:(NSString *)service; 35 | + (BOOL)removeAllItemsForService:(NSString *)service accessGroup:(NSString *)accessGroup; 36 | 37 | + (UICKeyChainStore *)keyChainStore; 38 | + (UICKeyChainStore *)keyChainStoreWithService:(NSString *)service; 39 | + (UICKeyChainStore *)keyChainStoreWithService:(NSString *)service accessGroup:(NSString *)accessGroup; 40 | - (id)init; 41 | - (id)initWithService:(NSString *)service; 42 | - (id)initWithService:(NSString *)service accessGroup:(NSString *)accessGroup; 43 | 44 | - (void)setString:(NSString *)string forKey:(NSString *)key; 45 | - (NSString *)stringForKey:(NSString *)key; 46 | 47 | - (void)setData:(NSData *)data forKey:(NSString *)key; 48 | - (NSData *)dataForKey:(NSString *)key; 49 | 50 | - (void)removeItemForKey:(NSString *)key; 51 | - (void)removeAllItems; 52 | 53 | - (void)synchronize; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIAlertView+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertView+WTRequestCenter.h 3 | // WTRequestCenter 4 | // 5 | // Created by SongWentong on 14-10-16. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIAlertView (WTRequestCenter) 12 | +(void)showAlertWithMessage:(NSString*)message; 13 | +(void)showAlertWithTitle:(NSString*)title message:(NSString*)message duration:(NSTimeInterval)time; 14 | @end 15 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIAlertView+WTRequestCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertView+WTRequestCenter.m 3 | // WTRequestCenter 4 | // 5 | // Created by SongWentong on 14-10-16. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import "UIAlertView+WTRequestCenter.h" 10 | 11 | @implementation UIAlertView (WTRequestCenter) 12 | +(void)showAlertWithMessage:(NSString*)message 13 | { 14 | [self showAlertWithTitle:nil message:message duration:1.0]; 15 | } 16 | 17 | +(void)showAlertWithTitle:(NSString*)title message:(NSString*)message duration:(NSTimeInterval)time 18 | { 19 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles: nil]; 20 | [alert show]; 21 | [alert performSelector:@selector(dismissAnimated:) withObject:@YES afterDelay:1.0]; 22 | 23 | } 24 | @end 25 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIApplication+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIApplication+WTRequestCenter.h 3 | // WTRequestCenter 4 | // 5 | // Created by SongWentong on 14/12/11. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIApplication (WTRequestCenter) 12 | //程序版本号 13 | +(NSString*)WTAppVersion; 14 | 15 | //build 号 16 | +(NSString*)WTAppBuild; 17 | @end 18 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIApplication+WTRequestCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIApplication+WTRequestCenter.m 3 | // WTRequestCenter 4 | // 5 | // Created by SongWentong on 14/12/11. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import "UIApplication+WTRequestCenter.h" 10 | 11 | @implementation UIApplication (WTRequestCenter) 12 | 13 | 14 | 15 | 16 | 17 | 18 | //版本号 19 | +(NSString*)WTAppVersion 20 | { 21 | NSString *version = [[NSBundle mainBundle] infoDictionary][(NSString *)kCFBundleInfoDictionaryVersionKey]; 22 | return version; 23 | } 24 | 25 | //build 号 26 | +(NSString*)WTAppBuild 27 | { 28 | NSString *build = [[NSBundle mainBundle] infoDictionary][(NSString *)kCFBundleVersionKey]; 29 | return build; 30 | } 31 | @end 32 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIButton+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+WTImageCache.h 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-7-30. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | /* 9 | 这是一个方便的缓存式网络请求的缓存库,在网络不好 10 | 或者没有网络的情况下方便读取缓存来看。 11 | 12 | 使用方法很简单,只需要传URL和参数就可以了。 13 | 14 | 还提供上传图片功能,下载图片功能,缓存图片功能 15 | 还有JSON解析功能,还提供来一个URL的表让你来填写 16 | 然后直接快捷取URL。 17 | 希望能帮到你,谢谢。 18 | 如果有任何问题可以在github上向我提出 19 | Mike 20 | 21 | */ 22 | 23 | #import 24 | @class WTURLRequestOperation; 25 | @interface UIButton (WTImageCache) 26 | 27 | @property (nonatomic,strong) WTURLRequestOperation *wtImageRequestOperation; 28 | @property (nonatomic,strong) WTURLRequestOperation *wtBackGroundImageRequestOperation; 29 | 30 | - (void)setImageForState:(UIControlState)state 31 | withURL:(NSString *)url; 32 | 33 | - (void)setImageForState:(UIControlState)state 34 | withURL:(NSString *)url 35 | placeholderImage:(UIImage *)placeholderImage; 36 | 37 | - (void)setBackgroundImage:(UIControlState)state 38 | withURL:(NSString *)url; 39 | 40 | - (void)setBackgroundImage:(UIControlState)state 41 | withURL:(NSString *)url 42 | placeholderImage:(UIImage *)placeholderImage; 43 | @end 44 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIButton+WTRequestCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+WTImageCache.m 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-7-30. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | 10 | 11 | #import "UIButton+WTRequestCenter.h" 12 | #import "WTRequestCenter.h" 13 | #import "WTRequestCenterMacro.h" 14 | #import "UIKit+WTRequestCenter.h" 15 | #import 16 | #import "WTURLRequestOperation.h" 17 | 18 | @implementation UIButton (WTImageCache) 19 | 20 | -(WTURLRequestOperation*)wtImageRequestOperation 21 | { 22 | WTURLRequestOperation *operation = (WTURLRequestOperation*)objc_getAssociatedObject(self, @"a"); 23 | return operation; 24 | } 25 | 26 | -(void)setWtImageRequestOperation:(WTURLRequestOperation *)wtImageRequestOperation 27 | { 28 | objc_setAssociatedObject(self, @"a", wtImageRequestOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 29 | } 30 | 31 | -(WTURLRequestOperation*)wtBackGroundImageRequestOperation 32 | { 33 | WTURLRequestOperation *operation = (WTURLRequestOperation*)objc_getAssociatedObject(self, @"b"); 34 | return operation; 35 | } 36 | 37 | -(void)setWtBackGroundImageRequestOperation:(WTURLRequestOperation *)wtBackGroundImageRequestOperation 38 | { 39 | objc_setAssociatedObject(self, @"b", wtBackGroundImageRequestOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 40 | } 41 | 42 | 43 | 44 | - (void)setImageForState:(UIControlState)state 45 | withURL:(NSString *)url 46 | { 47 | [self setImageForState:state withURL:url placeholderImage:nil]; 48 | } 49 | - (void)setImageForState:(UIControlState)state 50 | withURL:(NSString *)url 51 | placeholderImage:(UIImage *)placeholderImage 52 | { 53 | [self setImage:placeholderImage forState:state]; 54 | 55 | if (self.wtImageRequestOperation) { 56 | [self.wtImageRequestOperation cancel]; 57 | self.wtImageRequestOperation = nil; 58 | } 59 | 60 | if (!url) { 61 | return; 62 | } 63 | __weak UIButton *weakSelf = self; 64 | 65 | 66 | WTURLRequestOperation *operation = [WTRequestCenter testGetWithURL:url parameters:nil option:WTRequestCenterCachePolicyCacheElseWeb finished:^(NSURLResponse *response, NSData *data) { 67 | 68 | [UIImage imageWithData:data complectionHandler:^(UIImage *image) { 69 | 70 | if (image) { 71 | if (!weakSelf) return; 72 | __strong UIButton *strongSelf = weakSelf; 73 | 74 | dispatch_sync(dispatch_get_main_queue(), ^{ 75 | // strongSelf.image = image; 76 | [strongSelf setImage:image forState:state]; 77 | [strongSelf setNeedsLayout]; 78 | 79 | }); 80 | strongSelf.wtImageRequestOperation = nil; 81 | } 82 | }]; 83 | [[WTRequestCenter sharedQueue] addOperationWithBlock:^{ 84 | // UIImage *image = [UIImage imageWithData:data]; 85 | 86 | }]; 87 | 88 | } failed:^(NSURLResponse *response, NSError *error) { 89 | 90 | // if (!weakSelf) return; 91 | // __strong UIImageView *strongSelf = weakSelf; 92 | // strongSelf.wtImageRequestOperation = nil; 93 | }]; 94 | 95 | self.wtImageRequestOperation = operation; 96 | 97 | } 98 | 99 | - (void)setBackgroundImage:(UIControlState)state 100 | withURL:(NSString *)url 101 | { 102 | [self setBackgroundImage:state withURL:url placeholderImage:nil]; 103 | } 104 | 105 | - (void)setBackgroundImage:(UIControlState)state 106 | withURL:(NSString *)url 107 | placeholderImage:(UIImage *)placeholderImage 108 | { 109 | 110 | if (self.wtBackGroundImageRequestOperation) { 111 | [self.wtBackGroundImageRequestOperation cancel]; 112 | self.wtBackGroundImageRequestOperation = nil; 113 | } 114 | [self setBackgroundImage:placeholderImage forState:state]; 115 | 116 | if (!url) { 117 | return; 118 | } 119 | __weak UIButton *weakSelf = self; 120 | 121 | self.wtBackGroundImageRequestOperation = [WTRequestCenter testGetWithURL:url parameters:nil option:WTRequestCenterCachePolicyCacheElseWeb finished:^(NSURLResponse *response, NSData *data) { 122 | 123 | 124 | [UIImage imageWithData:data complectionHandler:^(UIImage *image) { 125 | if (image) { 126 | if (weakSelf) { 127 | __strong UIButton *strongSelf = weakSelf; 128 | dispatch_sync(dispatch_get_main_queue(), ^{ 129 | [strongSelf setBackgroundImage:image forState:state]; 130 | [strongSelf setNeedsLayout]; 131 | }); 132 | 133 | } 134 | } 135 | 136 | }]; 137 | 138 | } failed:^(NSURLResponse *response, NSError *error) { 139 | 140 | }]; 141 | 142 | } 143 | 144 | 145 | @end 146 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIColor+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+FastCreating.h 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-8-14. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIColor (WTRequestCenter) 12 | 13 | //用色值创建颜色 RGB都是number 14 | + (UIColor*)WTcolorWithFloat:(CGFloat)number; 15 | 16 | //用RGB创建颜色,分别设置RGB,无需除以255 17 | + (UIColor *)WTcolorWithRed:(CGFloat)red 18 | green:(CGFloat)green 19 | blue:(CGFloat)blue; 20 | 21 | //用RGBA创建颜色,无需除以255.0 22 | + (UIColor *)WTcolorWithRed:(CGFloat)red 23 | green:(CGFloat)green 24 | blue:(CGFloat)blue 25 | alpha:(CGFloat)alpha; 26 | 27 | // 16 进制颜色创建 28 | + (UIColor *)WTcolorWithHexString:(NSString *)str; 29 | // 根据hex字符串和alpha创建颜色 30 | + (UIColor *)WTcolorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIColor+WTRequestCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+FastCreating.m 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-8-14. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import "UIColor+WTRequestCenter.h" 10 | 11 | @implementation UIColor (WTRequestCenter) 12 | 13 | + (UIColor*)WTcolorWithFloat:(CGFloat)number 14 | { 15 | return [self WTcolorWithRed:number green:number blue:number]; 16 | } 17 | 18 | + (UIColor *)WTcolorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue{ 19 | return [self WTcolorWithRed:red green:green blue:blue alpha:1.0]; 20 | } 21 | + (UIColor *)WTcolorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha 22 | { 23 | UIColor *color = nil; 24 | color = [UIColor colorWithRed:red/255.00 green:green/255.00 blue:blue/255.00 alpha:alpha]; 25 | return color; 26 | } 27 | 28 | 29 | + (NSUInteger)integerValueFromHexString:(NSString *)hexString { 30 | NSScanner *scanner = [NSScanner scannerWithString:hexString]; 31 | unsigned int result; 32 | [scanner scanHexInt:&result]; 33 | return result; 34 | } 35 | 36 | + (UIColor *)WTcolorWithHexString:(NSString *)str 37 | { 38 | return [self WTcolorWithHexString:str alpha:1.0]; 39 | } 40 | 41 | + (UIColor *)WTcolorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha { 42 | // #rgb = #rrggbb 43 | 44 | if ([hexString hasPrefix:@"#"]) { 45 | hexString = [hexString substringFromIndex:1]; 46 | } 47 | 48 | if ([hexString length] == 3) { 49 | NSString *oneR = [hexString substringWithRange:NSMakeRange(0, 1)]; 50 | NSString *oneG = [hexString substringWithRange:NSMakeRange(1, 1)]; 51 | NSString *oneB = [hexString substringWithRange:NSMakeRange(2, 1)]; 52 | 53 | hexString = [NSString stringWithFormat:@"%@%@%@%@%@%@", oneR, oneR, oneG, oneG, oneB, oneB]; 54 | } 55 | 56 | if ([hexString length]!=6) { 57 | return nil; 58 | } 59 | 60 | CGFloat red = [self integerValueFromHexString:[hexString substringWithRange:NSMakeRange(0, 2)]]; 61 | CGFloat green = [self integerValueFromHexString:[hexString substringWithRange:NSMakeRange(2, 2)]]; 62 | CGFloat blue = [self integerValueFromHexString:[hexString substringWithRange:NSMakeRange(4, 2)]]; 63 | 64 | return [self colorWithRed:red green:green blue:blue alpha:alpha]; 65 | } 66 | 67 | 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIDevice+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+WTRequestCenter.h 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-8-12. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | // install 9 | // git clone https://github.com/swtlovewtt/WTRequestCenter 10 | #import 11 | 12 | @interface UIDevice (WTRequestCenter) 13 | 14 | 15 | //UUID 唯一标示符 16 | +(NSString*)WTUUID; 17 | 18 | +(CGFloat)systemVersion; 19 | @end 20 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIDevice+WTRequestCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIDevice+WTRequestCenter.m 3 | // WTRequestCenter 4 | // 5 | // Created by song on 14-8-15. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import "UIDevice+WTRequestCenter.h" 10 | 11 | @implementation UIDevice (WTRequestCenter) 12 | 13 | +(NSString*)WTUUID 14 | { 15 | NSString *uuid = @""; 16 | UIDevice *device = [UIDevice currentDevice]; 17 | 18 | 19 | if ([device.systemVersion floatValue]>=6.0) { 20 | NSUUID *uid = device.identifierForVendor; 21 | uuid = [uid UUIDString]; 22 | }else 23 | { 24 | 25 | // SEL selector = @selector(uniqueIdentifier); 26 | // uuid = [device performSelector:selector]; 27 | 28 | } 29 | 30 | return uuid; 31 | } 32 | 33 | 34 | +(CGFloat)systemVersion 35 | { 36 | CGFloat version = 0; 37 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) 38 | UIDevice *currentDevice = [UIDevice currentDevice]; 39 | version = currentDevice.systemVersion.floatValue; 40 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) 41 | NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; 42 | version = [[sv objectForKey:@"ProductVersion"] floatValue]; 43 | #endif 44 | 45 | return version; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIImage+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | /** 4 | UIImage (animatedGIF) 5 | 6 | This category adds class methods to `UIImage` to create an animated `UIImage` from an animated GIF. 7 | */ 8 | @interface UIImage (WTRequestCenter) 9 | 10 | #pragma mark - 建议的方法 11 | /*! 12 | 可缓存的,自动区分本地和网络的方法,建议用这个 13 | */ 14 | +(void)gifImageWithURL:(NSString*)url 15 | completion:(void(^)(UIImage* image))completion; 16 | 17 | 18 | /*! 19 | 通常不会直接用到的方法 20 | */ 21 | +(void)imageWithURL:(NSString*)url 22 | comelectionHandler:(void(^)(UIImage* image))comelectionHandler; 23 | 24 | 25 | /*! 26 | 通常不会直接用到的方法,作为UIImageView和UIButton的辅助方法 27 | */ 28 | +(void)imageWithData:(NSData *)data complectionHandler:(void(^)(UIImage *image))complection; 29 | 30 | //对UIView进行快照 31 | + (UIImage *)snapshot:(UIView *)view; 32 | 33 | 34 | 35 | 36 | 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIImage+WTRequestCenter.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #import "UIImage+WTRequestCenter.h" 7 | #import 8 | 9 | #if __has_feature(objc_arc) 10 | #define toCF (__bridge CFTypeRef) 11 | #define fromCF (__bridge id) 12 | #else 13 | #define toCF (CFTypeRef) 14 | #define fromCF (id) 15 | #endif 16 | #import "WTRequestCenter.h" 17 | @implementation UIImage (WTRequestCenter) 18 | 19 | static int delayCentisecondsForImageAtIndex(CGImageSourceRef const source, size_t const i) { 20 | int delayCentiseconds = 1; 21 | CFDictionaryRef const properties = CGImageSourceCopyPropertiesAtIndex(source, i, NULL); 22 | if (properties) { 23 | CFDictionaryRef const gifProperties = CFDictionaryGetValue(properties, kCGImagePropertyGIFDictionary); 24 | if (gifProperties) { 25 | NSNumber *number = fromCF CFDictionaryGetValue(gifProperties, kCGImagePropertyGIFUnclampedDelayTime); 26 | if (number == NULL || [number doubleValue] == 0) { 27 | number = fromCF CFDictionaryGetValue(gifProperties, kCGImagePropertyGIFDelayTime); 28 | } 29 | if ([number doubleValue] > 0) { 30 | // Even though the GIF stores the delay as an integer number of centiseconds, ImageIO “helpfully” converts that to seconds for us. 31 | delayCentiseconds = (int)lrint([number doubleValue] * 100); 32 | } 33 | } 34 | CFRelease(properties); 35 | } 36 | return delayCentiseconds; 37 | } 38 | 39 | static void createImagesAndDelays(CGImageSourceRef source, size_t count, CGImageRef imagesOut[count], int delayCentisecondsOut[count]) { 40 | for (size_t i = 0; i < count; ++i) { 41 | imagesOut[i] = CGImageSourceCreateImageAtIndex(source, i, NULL); 42 | delayCentisecondsOut[i] = delayCentisecondsForImageAtIndex(source, i); 43 | } 44 | } 45 | 46 | static int sum(size_t const count, int const *const values) { 47 | int theSum = 0; 48 | for (size_t i = 0; i < count; ++i) { 49 | theSum += values[i]; 50 | } 51 | return theSum; 52 | } 53 | 54 | static int pairGCD(int a, int b) { 55 | if (a < b) 56 | return pairGCD(b, a); 57 | while (true) { 58 | int const r = a % b; 59 | if (r == 0) 60 | return b; 61 | a = b; 62 | b = r; 63 | } 64 | } 65 | 66 | static int vectorGCD(size_t const count, int const *const values) { 67 | int gcd = values[0]; 68 | for (size_t i = 1; i < count; ++i) { 69 | // Note that after I process the first few elements of the vector, `gcd` will probably be smaller than any remaining element. By passing the smaller value as the second argument to `pairGCD`, I avoid making it swap the arguments. 70 | gcd = pairGCD(values[i], gcd); 71 | } 72 | return gcd; 73 | } 74 | 75 | static NSArray *frameArray(size_t const count, CGImageRef const images[count], int const delayCentiseconds[count], int const totalDurationCentiseconds) { 76 | int const gcd = vectorGCD(count, delayCentiseconds); 77 | size_t const frameCount = totalDurationCentiseconds / gcd; 78 | UIImage *frames[frameCount]; 79 | for (size_t i = 0, f = 0; i < count; ++i) { 80 | UIImage *const frame = [UIImage imageWithCGImage:images[i]]; 81 | for (size_t j = delayCentiseconds[i] / gcd; j > 0; --j) { 82 | frames[f++] = frame; 83 | } 84 | } 85 | return [NSArray arrayWithObjects:frames count:frameCount]; 86 | } 87 | 88 | static void releaseImages(size_t const count, CGImageRef const images[count]) { 89 | for (size_t i = 0; i < count; ++i) { 90 | CGImageRelease(images[i]); 91 | } 92 | } 93 | 94 | static UIImage *animatedImageWithAnimatedGIFImageSource(CGImageSourceRef const source) { 95 | size_t const count = CGImageSourceGetCount(source); 96 | CGImageRef images[count]; 97 | int delayCentiseconds[count]; // in centiseconds 98 | createImagesAndDelays(source, count, images, delayCentiseconds); 99 | int const totalDurationCentiseconds = sum(count, delayCentiseconds); 100 | NSArray *const frames = frameArray(count, images, delayCentiseconds, totalDurationCentiseconds); 101 | UIImage *const animation = [UIImage animatedImageWithImages:frames duration:(NSTimeInterval)totalDurationCentiseconds / 100.0]; 102 | releaseImages(count, images); 103 | return animation; 104 | } 105 | 106 | static UIImage *animatedImageWithAnimatedGIFReleasingImageSource(CGImageSourceRef CF_RELEASES_ARGUMENT source) { 107 | if (source) { 108 | UIImage *const image = animatedImageWithAnimatedGIFImageSource(source); 109 | CFRelease(source); 110 | return image; 111 | } else { 112 | return nil; 113 | } 114 | } 115 | 116 | +(void)imageWithURLString:(NSString*)string 117 | comelectionHandler:(void(^)(UIImage* image))comelectionHandler 118 | { 119 | [self imageWithURL:string comelectionHandler:comelectionHandler]; 120 | } 121 | 122 | + (void)imageWithURL:(NSString*)url 123 | comelectionHandler:(void(^)(UIImage* image))comelectionHandler 124 | { 125 | NSURL *tempURL = [NSURL URLWithString:url]; 126 | NSURLRequest *request = [NSURLRequest requestWithURL:tempURL]; 127 | 128 | 129 | 130 | [WTRequestCenter doURLRequest:request finished:^(NSURLResponse *response, NSData *data) { 131 | 132 | [[WTRequestCenter sharedQueue] addOperationWithBlock:^{ 133 | if (comelectionHandler) { 134 | if (data) { 135 | 136 | UIImage *image = [UIImage imageWithData:data]; 137 | 138 | comelectionHandler(image); 139 | 140 | 141 | } 142 | } 143 | }]; 144 | 145 | 146 | } failed:^(NSURLResponse *response, NSError *error) { 147 | if (comelectionHandler) { 148 | comelectionHandler(nil); 149 | } 150 | }]; 151 | 152 | } 153 | 154 | + (UIImage *)animatedImageWithAnimatedGIFData:(NSData *)data { 155 | return animatedImageWithAnimatedGIFReleasingImageSource(CGImageSourceCreateWithData(toCF data, NULL)); 156 | } 157 | 158 | + (UIImage *)animatedImageWithAnimatedGIFURL:(NSURL *)url { 159 | 160 | return animatedImageWithAnimatedGIFReleasingImageSource(CGImageSourceCreateWithURL(toCF url, NULL)); 161 | } 162 | 163 | +(void)imageWithData:(NSData *)data complectionHandler:(void(^)(UIImage *image))complection 164 | { 165 | [[WTRequestCenter sharedQueue] addOperationWithBlock:^{ 166 | UIImage *image = [UIImage imageWithData:data]; 167 | if (complection) { 168 | complection(image); 169 | } 170 | }]; 171 | } 172 | 173 | +(void)gifImageWithURL:(NSString*)url completion:(void(^)(UIImage* image))completion 174 | { 175 | // BOOL isLocal; 176 | 177 | // 网络的 178 | if (!url) { 179 | return; 180 | } 181 | 182 | 183 | 184 | 185 | } 186 | 187 | 188 | + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size 189 | { 190 | CGRect rect = CGRectMake(0, 0, size.width, size.height); 191 | UIGraphicsBeginImageContext(rect.size); 192 | CGContextRef context = UIGraphicsGetCurrentContext(); 193 | 194 | CGContextSetFillColorWithColor(context, [color CGColor]); 195 | CGContextFillRect(context, rect); 196 | 197 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 198 | UIGraphicsEndImageContext(); 199 | return image; 200 | } 201 | 202 | 203 | + (UIImage *)snapshot:(UIView *)view 204 | { 205 | UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0); 206 | [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES]; 207 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 208 | UIGraphicsEndImageContext(); 209 | 210 | return image; 211 | } 212 | 213 | @end 214 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIImageView+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+WTImageCache.h 3 | // WTRequestCenter 4 | // 5 | // Created by song on 14-7-19. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | 9 | /* 10 | 这是一个方便的缓存式网络请求的缓存库,在网络不好 11 | 或者没有网络的情况下方便读取缓存来看。 12 | 13 | 使用方法很简单,只需要传URL和参数就可以了。 14 | 15 | 还提供上传图片功能,下载图片功能,缓存图片功能 16 | 还有JSON解析功能,还提供来一个URL的表让你来填写 17 | 然后直接快捷取URL。 18 | 希望能帮到你,谢谢。 19 | 如果有任何问题可以在github上向我提出 20 | Mike 21 | 22 | */ 23 | 24 | #import 25 | #import "WTRequestCenter.h" 26 | @interface UIImageView (WTRequestCenter) 27 | @property (nonatomic,strong,readonly) WTURLRequestOperation *wtImageRequestOperation; 28 | //下载图片 29 | - (void)setImageWithURL:(NSString*)url; 30 | //下载图片+placeholder 31 | - (void)setImageWithURL:(NSString*)url 32 | placeholderImage:(UIImage *)placeholder; 33 | 34 | -(void)setImageWithURL:(NSString *)url placeholderImage:(UIImage *)placeholder finished:(WTRequestFinishedBlock)finished failed:(WTRequestFailedBlock)failed; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIImageView+WTRequestCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+WTImageCache.m 3 | // WTRequestCenter 4 | // 5 | // Created by song on 14-7-19. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | 9 | #import "UIImageView+WTRequestCenter.h" 10 | #import 11 | #import "WTRequestCenterMacro.h" 12 | #import "UIImage+WTRequestCenter.h" 13 | #import "WTURLRequestOperation.h" 14 | 15 | @interface UIImageView() 16 | //@property (nonatomic,strong,readwrite) WTURLRequestOperation *wtImageRequestOperation; 17 | @property (nonatomic,strong ,readwrite) WTURLRequestOperation *myOperation; 18 | @end 19 | @implementation UIImageView (WTRequestCenter) 20 | 21 | 22 | 23 | 24 | 25 | -(WTURLRequestOperation*)wtImageRequestOperation 26 | { 27 | WTURLRequestOperation *operation = (WTURLRequestOperation*)objc_getAssociatedObject(self, @"a"); 28 | return operation; 29 | } 30 | 31 | -(void)setWtImageRequestOperation:(WTURLRequestOperation *)wtImageRequestOperation 32 | { 33 | objc_setAssociatedObject(self, @"a", wtImageRequestOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 34 | } 35 | 36 | 37 | 38 | - (void)setImageWithURL:(NSString *)url 39 | { 40 | [self setImageWithURL:url placeholderImage:nil]; 41 | } 42 | 43 | - (void)setImageWithURL:(NSString *)url placeholderImage:(UIImage *)placeholder 44 | { 45 | 46 | [self setImageWithURL:url placeholderImage:placeholder finished:nil failed:nil]; 47 | } 48 | 49 | -(void)setImageWithURL:(NSString *)url placeholderImage:(UIImage *)placeholder finished:(WTRequestFinishedBlock)finished failed:(WTRequestFailedBlock)failed 50 | { 51 | if (self.wtImageRequestOperation) { 52 | [self.wtImageRequestOperation cancel]; 53 | self.wtImageRequestOperation = nil; 54 | } 55 | self.image = placeholder; 56 | if (url) { 57 | __weak UIImageView *wself = self; 58 | 59 | 60 | WTURLRequestOperation *operation = [WTRequestCenter testGetWithURL:url parameters:nil option:WTRequestCenterCachePolicyCacheElseWeb finished:^(NSURLResponse *response, NSData *data) { 61 | 62 | [UIImage imageWithData:data complectionHandler:^(UIImage *image) { 63 | 64 | if (image) { 65 | if (!wself) return; 66 | __strong UIImageView *strongSelf = wself; 67 | 68 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 69 | strongSelf.image = image; 70 | [strongSelf setNeedsLayout]; 71 | }]; 72 | strongSelf.wtImageRequestOperation = nil; 73 | strongSelf.wtImageRequestOperation = nil; 74 | } 75 | 76 | 77 | }]; 78 | if (finished) { 79 | dispatch_sync(dispatch_get_main_queue(), ^{ 80 | finished(response,data); 81 | }); 82 | } 83 | 84 | } failed:^(NSURLResponse *response, NSError *error) { 85 | if (!wself) return; 86 | __strong UIImageView *strongSelf = wself; 87 | if (failed) { 88 | failed(self.wtImageRequestOperation.response,self.wtImageRequestOperation.error); 89 | } 90 | strongSelf.wtImageRequestOperation = nil; 91 | }]; 92 | 93 | self.wtImageRequestOperation = operation; 94 | }else 95 | { 96 | 97 | } 98 | } 99 | 100 | 101 | 102 | 103 | @end 104 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIKit+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIKit+WTRequestCenter.h 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-8-12. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | /* 9 | 这是一个方便的缓存式网络请求的缓存库,在网络不好 10 | 或者没有网络的情况下方便读取缓存来看。 11 | 12 | 使用方法很简单,只需要传URL和参数就可以了。 13 | 14 | 还提供上传图片功能,下载图片功能,缓存图片功能 15 | 还有JSON解析功能,还提供来一个URL的表让你来填写 16 | 然后直接快捷取URL。 17 | 希望能帮到你,谢谢。 18 | 如果有任何问题可以在github上向我提出 19 | Mike 20 | 21 | */ 22 | /* 23 | 使用注意 24 | 使用gif图的时候需要import一个ImageIO.framework 25 | */ 26 | #import 27 | 28 | #ifndef WTRequestCenter_UIKit_WTRequestCenter_h 29 | #define WTRequestCenter_UIKit_WTRequestCenter_h 30 | #import "UIButton+WTRequestCenter.h" 31 | #import "UIImageView+WTRequestCenter.h" 32 | #import "UIImage+WTRequestCenter.h" 33 | #import "UIColor+WTRequestCenter.h" 34 | #import "UIDevice+WTRequestCenter.h" 35 | #import "UIWebView+WTRequestCenter.h" 36 | #import "UIAlertView+WTRequestCenter.h" 37 | #import "WTImageViewer.h" 38 | #import "WTNetworkActivityIndicatorManager.h" 39 | #import "UIScreen+WTRequestCenter.h" 40 | #import "UIApplication+WTRequestCenter.h" 41 | #import "WTDataSaver.h" 42 | 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIScreen+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIScreen+WTRequestCenter.h 3 | // WTRequestCenter 4 | // 5 | // Created by SongWentong on 14/11/27. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIScreen (WTRequestCenter) 12 | //屏幕宽度 13 | +(CGFloat)screenWidth; 14 | 15 | //屏幕高度 16 | +(CGFloat)screenHeight; 17 | 18 | //屏幕大小 19 | +(CGSize)screenSize; 20 | 21 | /*! 22 | 把320标准换算成当前屏幕标准 23 | */ 24 | +(CGFloat)convert320ToCurrentWidth:(CGFloat)width; 25 | 26 | /*! 27 | 把320标准的点换算成当前屏幕标准 28 | */ 29 | +(CGPoint)convert320ToCurrentPoint:(CGPoint)point; 30 | 31 | 32 | /*! 33 | 把320标准换算成当前屏幕标准 34 | */ 35 | +(CGRect)convert320ToCurrentRect:(CGRect)rect; 36 | @end 37 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIScreen+WTRequestCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIScreen+WTRequestCenter.m 3 | // WTRequestCenter 4 | // 5 | // Created by SongWentong on 14/11/27. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import "UIScreen+WTRequestCenter.h" 10 | 11 | @implementation UIScreen (WTRequestCenter) 12 | +(CGFloat)screenWidth 13 | { 14 | return CGRectGetWidth([UIScreen mainScreen].bounds); 15 | } 16 | 17 | +(CGFloat)screenHeight 18 | { 19 | return CGRectGetHeight([UIScreen mainScreen].bounds); 20 | } 21 | 22 | +(CGSize)screenSize 23 | { 24 | return [UIScreen mainScreen].bounds.size; 25 | } 26 | 27 | 28 | +(CGFloat)convert320ToCurrentWidth:(CGFloat)width 29 | { 30 | if (width==[self screenHeight]) { 31 | // 在宽度等于屏幕宽度时防止出现误差 32 | return width; 33 | } 34 | CGFloat result = 0; 35 | CGFloat multiple = [self screenWidth]/320.0; 36 | result = width * multiple; 37 | return result; 38 | } 39 | 40 | +(CGPoint)convert320ToCurrentPoint:(CGPoint)point 41 | { 42 | CGPoint result; 43 | CGFloat multiple = [self screenWidth]/320.0; 44 | result = CGPointMake(point.x*multiple, point.y*multiple); 45 | 46 | return result; 47 | } 48 | 49 | 50 | +(CGRect)convert320ToCurrentRect:(CGRect)rect 51 | { 52 | CGRect result; 53 | CGFloat multiple = [self screenWidth]/320.0; 54 | result = CGRectMake(rect.origin.x*multiple, rect.origin.y*multiple, rect.size.width*multiple, rect.size.height*multiple); 55 | 56 | return result; 57 | } 58 | @end 59 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIWebView+WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIWebView+WTRequestCenter.h 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-9-28. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "WTRequestCenter.h" 11 | @interface UIWebView (WTRequestCenter) 12 | 13 | -(void)loadWithURL:(NSString*)url 14 | option:(WTRequestCenterCachePolicy)option; 15 | 16 | 17 | 18 | - (void)loadRequest:(NSURLRequest *)request 19 | option:(WTRequestCenterCachePolicy)option; 20 | @end 21 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/UIWebView+WTRequestCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIWebView+WTRequestCenter.m 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-9-28. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import "UIWebView+WTRequestCenter.h" 10 | 11 | @implementation UIWebView (WTRequestCenter) 12 | -(void)loadWithURL:(NSString*)url 13 | option:(WTRequestCenterCachePolicy)option 14 | { 15 | NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; 16 | [self loadRequest:request option:option]; 17 | 18 | } 19 | 20 | - (void)loadRequest:(NSURLRequest *)request 21 | option:(WTRequestCenterCachePolicy)option 22 | { 23 | 24 | if ([self isLoading]) { 25 | [self stopLoading]; 26 | } 27 | [WTRequestCenter doURLRequest:request 28 | option:option 29 | finished:^(NSURLResponse *response, NSData *data) { 30 | [self loadData:data 31 | MIMEType:@"text/html" 32 | textEncodingName:@"utf-8" 33 | baseURL:nil]; 34 | } failed:^(NSURLResponse *response, NSError *error) { 35 | 36 | }]; 37 | } 38 | @end 39 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/WTDataSaver.h: -------------------------------------------------------------------------------- 1 | // 2 | // WTDataSaver.h 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-8-7. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | /* 9 | 这是一个快捷文件存取工具,由于我使用中总会遇到一些 10 | 需要缓存的数据,于是我就想写一个数据缓存工具,我把数据 11 | 存到Library下的Cache下的WTDataSaver下,方便管理。 12 | 13 | 这个库提供了许多快捷存取文件的功能,方便使用。 14 | 15 | Mike 16 | */ 17 | #import 18 | #import 19 | @interface WTDataSaver : NSObject 20 | 21 | #pragma mark - 存数据 Save Data 22 | //存数据(都是异步) 23 | +(void)saveData:(NSData*)data withIndex:(NSInteger)index; 24 | +(void)saveData:(NSData*)data withName:(NSString*)name; 25 | //完成回调 26 | +(void)saveData:(NSData *)data 27 | withIndex:(NSInteger)index 28 | completion:(void (^)())completion; 29 | 30 | +(void)saveData:(NSData*)data 31 | withName:(NSString*)name 32 | completion:(void(^)())completion; 33 | 34 | 35 | 36 | #pragma mark - 读数据 Read Data 37 | 38 | 39 | //异步取数据(推荐) 40 | +(void)dataWithIndex:(NSInteger)index 41 | completion:(void(^)(NSData*data))completion; 42 | 43 | +(void)dataWithName:(NSString*)name 44 | completion:(void(^)(NSData*data))completion; 45 | 46 | //根据url获取文件,分线程回调 47 | +(void)dataWithURL:(NSString*)url 48 | completionHandler:(void (^)(NSData *data))completion; 49 | 50 | /*! 51 | 删除所有本地数据 52 | */ 53 | +(void)clearAllData; 54 | 55 | 56 | 57 | #pragma mark - 工具 58 | //适用范围 2.0+ 59 | +(NSData*)base64EncodedData:(NSData*)data; 60 | +(NSData*)decodeBase64Data:(NSData*)data; 61 | //Availability 62 | //Available in iOS 2.0 and later. 63 | 64 | 65 | +(float)osVersion; 66 | 67 | #pragma mark - 对象转换 68 | //用于对象和Data的转换,类型可以是NSDictionary或者NSArray 69 | +(NSData*)dataWithJSONObject:(id)obj; 70 | +(id)JSONObjectWithData:(NSData*)data; 71 | 72 | 73 | //根据文件名返回文件路径,用于自定义储存NSDicitonary,NSString和NSArray 74 | +(NSString*)pathWithName:(NSString*)name; 75 | 76 | #pragma mark - 清数据 RemoveAllData 77 | +(void)removeAllData; 78 | 79 | #pragma mark - 大小 file Size 80 | +(void)fileSizeComplection:(void(^)(NSInteger size))complection; 81 | 82 | 83 | @end 84 | /* 85 | index占用表 86 | 1:A页面XX数据 87 | 2:B页面XX数据 88 | 3:C页面XX数据 89 | 90 | */ 91 | 92 | /* 93 | name 占用表 94 | a:a页面a数据 95 | b:b页面b数据 96 | c:c页面c数据 97 | */ 98 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/WTImageViewer.h: -------------------------------------------------------------------------------- 1 | // 2 | // WTImageViewer.h 3 | // WTRequestCenter 4 | // 5 | // Created by song on 14/10/19. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | @interface WTImageScrollView : UIScrollView 11 | { 12 | 13 | } 14 | 15 | -(instancetype)initWithFrame:(CGRect)frame imageURL:(NSString*)url; 16 | @property (nonatomic,retain) UIButton *imageButton; 17 | @property (nonatomic,readonly,copy) NSString *imageURL; 18 | @end 19 | @class WTImageViewer; 20 | @protocol WTImageViewerDelegate 21 | 22 | -(void)WTImageViewer:(WTImageViewer*)viewer pressImageWithIndex:(NSInteger)index; 23 | 24 | @end 25 | @interface WTImageViewer : UIView 26 | { 27 | UIScrollView *myScrollView; 28 | 29 | 30 | NSMutableArray *imageViewArray; 31 | 32 | 33 | NSMutableArray *buttonArray; 34 | 35 | } 36 | @property (nonatomic) BOOL zoomEnable; 37 | @property (nonatomic,weak) id delegate; 38 | - (instancetype)initWithFrame:(CGRect)frame urls:(NSArray*)urls; 39 | @property (nonatomic,copy) NSArray *imageUrls; 40 | @property (NS_NONATOMIC_IOSONLY, readonly) NSUInteger currentPageIndex; 41 | 42 | 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/WTImageViewer.m: -------------------------------------------------------------------------------- 1 | // 2 | // WTImageViewer.m 3 | // WTRequestCenter 4 | // 5 | // Created by song on 14/10/19. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import "WTImageViewer.h" 10 | #import "UIKit+WTRequestCenter.h" 11 | 12 | 13 | @interface WTImageScrollView() 14 | @property (nonatomic,copy,readwrite) NSString *imageURL; 15 | @end 16 | @implementation WTImageScrollView 17 | -(instancetype)initWithFrame:(CGRect)frame imageURL:(NSString*)url 18 | { 19 | self = [self initWithFrame:frame]; 20 | if (self) { 21 | // self.backgroundColor = [UIColor greenColor]; 22 | self.imageURL = url; 23 | self.imageButton = [UIButton buttonWithType:UIButtonTypeCustom]; 24 | _imageButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 25 | _imageButton.frame = self.bounds; 26 | _imageButton.contentMode = UIViewContentModeScaleAspectFit; 27 | 28 | [_imageButton setImageForState:UIControlStateNormal withURL:url]; 29 | [self addSubview:_imageButton]; 30 | } 31 | return self; 32 | } 33 | /* 34 | // Only override drawRect: if you perform custom drawing. 35 | // An empty implementation adversely affects performance during animation. 36 | - (void)drawRect:(CGRect)rect { 37 | // Drawing code 38 | } 39 | */ 40 | 41 | @end 42 | @implementation WTImageViewer 43 | - (instancetype)initWithFrame:(CGRect)frame 44 | { 45 | self = [super initWithFrame:frame]; 46 | if (self) { 47 | 48 | } 49 | return self; 50 | } 51 | 52 | - (instancetype)initWithFrame:(CGRect)frame urls:(NSArray*)urls 53 | { 54 | self = [self initWithFrame:frame]; 55 | if (self) { 56 | imageViewArray = [[NSMutableArray alloc] init]; 57 | CGFloat width = CGRectGetWidth(frame); 58 | CGFloat height = CGRectGetHeight(frame); 59 | myScrollView = [[UIScrollView alloc] initWithFrame:frame]; 60 | myScrollView.delegate = self; 61 | myScrollView.contentSize = CGSizeMake(width*[urls count], height); 62 | myScrollView.pagingEnabled = YES; 63 | [self addSubview:myScrollView]; 64 | 65 | self.imageUrls = urls; 66 | 67 | [_imageUrls enumerateObjectsUsingBlock:^(NSString* url, NSUInteger idx, BOOL *stop) 68 | { 69 | CGRect frame = CGRectMake(320*idx, 0, width, height); 70 | WTImageScrollView *scrollView = [[WTImageScrollView alloc] initWithFrame:frame imageURL:url]; 71 | scrollView.maximumZoomScale = 4; 72 | scrollView.minimumZoomScale = 1; 73 | scrollView.delegate = self; 74 | [scrollView.imageButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; 75 | [imageViewArray addObject:scrollView]; 76 | [myScrollView addSubview:scrollView]; 77 | 78 | 79 | }]; 80 | myScrollView.backgroundColor = [UIColor blackColor]; 81 | 82 | } 83 | return self; 84 | } 85 | 86 | 87 | -(NSUInteger)currentPageIndex 88 | { 89 | CGPoint p = myScrollView.contentOffset; 90 | NSInteger page = p.x/CGRectGetWidth(self.frame); 91 | return page; 92 | } 93 | 94 | -(void)buttonPressed:(UIButton*)sender 95 | { 96 | // NSLog(@"%s",__func__); 97 | [_delegate WTImageViewer:self pressImageWithIndex:[self currentPageIndex]]; 98 | } 99 | 100 | #pragma mark - UIScrollViewDelegate 101 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 102 | { 103 | if ([scrollView isEqual:myScrollView]) { 104 | [imageViewArray enumerateObjectsUsingBlock:^(WTImageScrollView *tempScrollView, NSUInteger idx, BOOL *stop) { 105 | tempScrollView.zoomScale = 1.0; 106 | }]; 107 | } 108 | 109 | } 110 | - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 111 | { 112 | 113 | // NSInteger page = scrollView.contentOffset.x/scrollView.frame.size.width; 114 | if (_zoomEnable) { 115 | if ([scrollView isEqual:myScrollView]) { 116 | return nil; 117 | }else 118 | { 119 | WTImageScrollView *temp = (WTImageScrollView*)scrollView; 120 | return temp.imageButton; 121 | } 122 | }else 123 | { 124 | return nil; 125 | } 126 | 127 | 128 | } 129 | /* 130 | // Only override drawRect: if you perform custom drawing. 131 | // An empty implementation adversely affects performance during animation. 132 | - (void)drawRect:(CGRect)rect { 133 | // Drawing code 134 | } 135 | */ 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/WTNetworkActivityIndicatorManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // WTNetworkActivityIndicatorManager.h 3 | // WTRequestCenter 4 | // 5 | // Created by song on 14/10/24. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | 8 | 9 | #import 10 | #import 11 | 12 | 13 | // 网络访问指示器,enable设置为YES后网络访问在状态栏有提示 14 | @interface WTNetworkActivityIndicatorManager : NSObject 15 | 16 | @property (nonatomic, assign, getter = isEnabled) BOOL enabled; 17 | 18 | @property (readonly, nonatomic, assign) BOOL isNetworkActivityIndicatorVisible; 19 | 20 | + (instancetype)sharedManager; 21 | - (void)incrementActivityCount; 22 | - (void)decrementActivityCount; 23 | @end 24 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/WTNetworkActivityIndicatorManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // WTNetworkActivityIndicatorManager.m 3 | // WTRequestCenter 4 | // 5 | // Created by song on 14/10/24. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import "WTNetworkActivityIndicatorManager.h" 10 | #import "WTRequestCenter.h" 11 | @interface WTNetworkActivityIndicatorManager () 12 | @property (readwrite, nonatomic, assign) NSInteger activityCount; 13 | @property (readwrite, nonatomic, strong) NSTimer *activityIndicatorVisibilityTimer; 14 | @end 15 | //状态管理工具 16 | @implementation WTNetworkActivityIndicatorManager 17 | 18 | + (instancetype)sharedManager{ 19 | static WTNetworkActivityIndicatorManager *_sharedManager = nil; 20 | static dispatch_once_t oncePredicate; 21 | dispatch_once(&oncePredicate, ^{ 22 | _sharedManager = [[self alloc] init]; 23 | }); 24 | 25 | return _sharedManager; 26 | } 27 | 28 | - (instancetype)init 29 | { 30 | self = [super init]; 31 | if (self) { 32 | [self handleNotifications]; 33 | } 34 | return self; 35 | } 36 | - (void)dealloc 37 | { 38 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 39 | } 40 | -(void)handleNotifications 41 | { 42 | [[NSNotificationCenter defaultCenter] addObserverForName:WTNetworkingOperationDidStartNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { 43 | // if ([[[self class] requestFromNotification:note] URL]) { 44 | 45 | 46 | [self incrementActivityCount]; 47 | 48 | // } 49 | 50 | }]; 51 | 52 | 53 | 54 | [[NSNotificationCenter defaultCenter] addObserverForName:WTNetworkingOperationDidFinishNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { 55 | // if ([[[self class] requestFromNotification:note] URL]) { 56 | 57 | [self decrementActivityCount]; 58 | // } 59 | }]; 60 | } 61 | 62 | +(NSURLRequest*)requestFromNotification:(NSNotification*)notification 63 | { 64 | if ([[notification object] isKindOfClass:[NSURLRequest class]]) { 65 | return [notification object]; 66 | } 67 | return nil; 68 | } 69 | 70 | - (void)incrementActivityCount { 71 | [self willChangeValueForKey:@"activityCount"]; 72 | @synchronized(self) { 73 | _activityCount++; 74 | } 75 | 76 | [self didChangeValueForKey:@"activityCount"]; 77 | 78 | dispatch_async(dispatch_get_main_queue(), ^{ 79 | [self updateNetworkActivityIndicatorVisibilityDelayed]; 80 | }); 81 | } 82 | 83 | 84 | 85 | - (void)decrementActivityCount { 86 | [self willChangeValueForKey:@"activityCount"]; 87 | @synchronized(self) { 88 | #pragma clang diagnostic push 89 | #pragma clang diagnostic ignored "-Wgnu" 90 | _activityCount = MAX(_activityCount - 1, 0); 91 | #pragma clang diagnostic pop 92 | } 93 | [self didChangeValueForKey:@"activityCount"]; 94 | 95 | dispatch_async(dispatch_get_main_queue(), ^{ 96 | [self updateNetworkActivityIndicatorVisibilityDelayed]; 97 | }); 98 | } 99 | 100 | - (BOOL)isNetworkActivityIndicatorVisible { 101 | 102 | return self.activityCount > 0; 103 | } 104 | - (void)updateNetworkActivityIndicatorVisibilityDelayed { 105 | if (self.enabled) { 106 | // Delay hiding of activity indicator for a short interval, to avoid flickering 107 | 108 | if (![self isNetworkActivityIndicatorVisible]) { 109 | [self.activityIndicatorVisibilityTimer invalidate]; 110 | self.activityIndicatorVisibilityTimer = [NSTimer timerWithTimeInterval:0.17 target:self selector:@selector(updateNetworkActivityIndicatorVisibility) userInfo:nil repeats:NO]; 111 | [[NSRunLoop mainRunLoop] addTimer:self.activityIndicatorVisibilityTimer forMode:NSRunLoopCommonModes]; 112 | } else { 113 | [self performSelectorOnMainThread:@selector(updateNetworkActivityIndicatorVisibility) withObject:nil waitUntilDone:NO modes:@[NSRunLoopCommonModes]]; 114 | } 115 | } 116 | } 117 | 118 | - (void)updateNetworkActivityIndicatorVisibility { 119 | [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]]; 120 | } 121 | 122 | @end 123 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/UIKit+WTRequestCenter/WTRequestCenterMacro.h: -------------------------------------------------------------------------------- 1 | // 2 | // WTRequestCenterMacro.h 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-8-29. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #ifndef WTRequestCenter_WTRequestCenterMacro_h 10 | #define WTRequestCenter_WTRequestCenterMacro_h 11 | #define dispatch_main_sync_safe(block)\ 12 | if ([NSThread isMainThread]) {\ 13 | block();\ 14 | } else {\ 15 | dispatch_sync(dispatch_get_main_queue(), block);\ 16 | } 17 | 18 | #define dispatch_main_async_safe(block)\ 19 | if ([NSThread isMainThread]) {\ 20 | block();\ 21 | } else {\ 22 | dispatch_async(dispatch_get_main_queue(), block);\ 23 | } 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/WTRequestCenter/WTNetWork.h: -------------------------------------------------------------------------------- 1 | // 2 | // WTNetWork.h 3 | // WTRequestCenter 4 | // 5 | // Created by SongWentong on 14/12/29. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | /* 9 | 这是一个方便的缓存式网络请求的缓存库,在网络不好 10 | 或者没有网络的情况下方便读取缓存来看。 11 | 12 | 使用方法很简单,只需要传URL和参数就可以了。 13 | 14 | 还提供上传图片功能,下载图片功能,缓存图片功能 15 | 还有JSON解析功能,还提供来一个URL的表让你来填写 16 | 然后直接快捷取URL。 17 | 希望能帮到你,谢谢。 18 | 如果有任何问题可以在github上向我提出 19 | Mike 20 | 21 | */ 22 | #ifndef WTRequestCenter_WTNetWork_h 23 | #define WTRequestCenter_WTNetWork_h 24 | 25 | #if !__has_feature(objc_arc) 26 | #error WTRequestCenter must be built with ARC. 27 | // You can turn on ARC for only WTRequestCenter files by adding -fobjc-arc to the build phase for each of its files. 28 | #endif 29 | 30 | #import "WTRequestCenter.h" 31 | #import "WTURLRequestOperation.h" 32 | #import "WTURLRequestSerialization.h" 33 | #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) 34 | #import "WTURLSessionManager.h" 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/WTRequestCenter/WTRequestCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // WTRequestCenter.h 3 | // TestCache 4 | // 5 | // Created by song on 14-7-19. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | /* 9 | 这是一个方便的缓存式网络请求的缓存库,在网络不好 10 | 或者没有网络的情况下方便读取缓存来看。 11 | 12 | 使用方法很简单,只需要传URL和参数就可以了。 13 | 14 | 还提供上传图片功能,下载图片功能,缓存图片功能 15 | 还有JSON解析功能,还提供来一个URL的表让你来填写 16 | 然后直接快捷取URL。 17 | 希望能帮到你,谢谢。 18 | 如果有任何问题可以在github上向我提出 19 | Mike 20 | 21 | */ 22 | #import 23 | 24 | @class WTURLRequestSerialization; 25 | @protocol WTMultipartFormData; 26 | @class WTURLRequestOperation; 27 | 28 | #if ( ( defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) || \ 29 | ( defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 ) ) 30 | 31 | #endif 32 | 33 | 34 | 35 | /*! 36 | @enum NSURLRequestCachePolicy 37 | 38 | @constant WTRequestCenterCachePolicyNormal 39 | 基本请求,直接访问url,取得数据 40 | 41 | @constant WTRequestCenterCachePolicyCacheElseWeb 42 | 查看本地是否有缓存,如果有就使用,不管失效日期, 43 | 如果缓存中没有,就访问url 44 | 45 | @constant WTRequestCenterCachePolicyOnlyCache 46 | 只取本地的数据,如果本地数据为空也不访问网络 47 | 48 | @constant WTRequestCenterCachePolicyCacheAndRefresh 49 | 本地获取一次,网络获取一次。 50 | 如果本地有数据,网络获取不回调,如果本地没有数据,网络获取会回调 51 | 52 | 53 | @constant WTRequestCenterCachePolicyCacheAndWeb 54 | 本地获取一次,网络获取一次,都会回调。 55 | 注意:这种情况非常少见,只有调用网页的时候可能会用得到。 56 | 57 | */ 58 | 59 | typedef NS_ENUM(NSUInteger, WTRequestCenterCachePolicy) { 60 | WTRequestCenterCachePolicyNormal, 61 | WTRequestCenterCachePolicyCacheElseWeb, 62 | WTRequestCenterCachePolicyOnlyCache, 63 | WTRequestCenterCachePolicyCacheAndRefresh, 64 | WTRequestCenterCachePolicyCacheAndWeb 65 | }; 66 | 67 | 68 | //call back block 69 | typedef void (^WTRequestFinishedBlock)(NSURLResponse *response,NSData *data); 70 | typedef void (^WTRequestFailedBlock)(NSURLResponse *response,NSError *error); 71 | typedef void (^WTRequestComplectionBlock)(NSURLResponse *response,NSData *data,NSError *error); 72 | typedef void (^WTDownLoadProgressBlock)(NSUInteger bytesRead,long long totalBytesRead,long long totalBytesExpectedToRead); 73 | 74 | @interface WTRequestCenter : NSObject 75 | 76 | 77 | 78 | /*! 79 | just do a request 80 | */ 81 | +(void)doURLRequest:(NSURLRequest*)request 82 | finished:(WTRequestFinishedBlock)finished 83 | failed:(WTRequestFailedBlock)failed; 84 | 85 | /* 86 | do a request with cachePolicy 87 | */ 88 | +(void)doURLRequest:(NSURLRequest*)request 89 | option:(WTRequestCenterCachePolicy)option 90 | finished:(WTRequestFinishedBlock)finished 91 | failed:(WTRequestFailedBlock)failed; 92 | #pragma mark - GET 93 | 94 | //GET 95 | /*! 96 | Performs an asynchronous get request of the given 97 | url,parameters. When the request has completed or failed, 98 | corresponding block will be executed 99 | */ 100 | +(NSURLRequest*)getWithURL:(NSString*)url 101 | parameters:(NSDictionary*)parameters 102 | finished:(WTRequestFinishedBlock)finished 103 | failed:(WTRequestFailedBlock)failed; 104 | 105 | /*! 106 | Performs an asynchronous get request of the given 107 | url,parameters,cache pilicy. When the request has completed or failed, 108 | corresponding block will be executed,is there is a local 109 | response,it will be used. 110 | */ 111 | +(NSURLRequest*)getWithURL:(NSString*)url 112 | parameters:(NSDictionary *)parameters 113 | option:(WTRequestCenterCachePolicy)option 114 | finished:(WTRequestFinishedBlock)finished 115 | failed:(WTRequestFailedBlock)failed; 116 | 117 | 118 | 119 | 120 | 121 | #pragma mark - POST 122 | 123 | /*! 124 | Performs an asynchronous post request of the given 125 | url,parameters. When the request has completed or failed, 126 | corresponding block will be executed,is there is a local 127 | response,it will be used. 128 | */ 129 | +(NSURLRequest*)postWithURL:(NSString*)url 130 | parameters:(NSDictionary*)parameters 131 | finished:(WTRequestFinishedBlock)finished 132 | failed:(WTRequestFailedBlock)failed; 133 | 134 | /*! 135 | POST request 136 | */ 137 | +(NSURLRequest*)postWithURL:(NSString*)url 138 | parameters:(NSDictionary*)parameters 139 | constructingBodyWithBlock:(void (^)(id formData))block 140 | finished:(WTRequestFinishedBlock)finished 141 | failed:(WTRequestFailedBlock)failed; 142 | 143 | 144 | /*! 145 | PUT reqeust 146 | */ 147 | +(NSURLRequest*)putWithURL:(NSString*)url 148 | parameters:(NSDictionary*)parameters 149 | finished:(WTRequestFinishedBlock)finished 150 | failed:(WTRequestFailedBlock)failed; 151 | 152 | 153 | /*! 154 | Delete request 155 | */ 156 | +(NSURLRequest*)deleteWithURL:(NSString*)url 157 | parameters:(NSDictionary*)parameters 158 | finished:(WTRequestFinishedBlock)finished 159 | failed:(WTRequestFailedBlock)failed; 160 | 161 | 162 | /*! 163 | HEAD 请求 164 | */ 165 | +(NSURLRequest*)headWithURL:(NSString*)url 166 | parameters:(NSDictionary*)parameters 167 | finished:(WTRequestFinishedBlock)finished 168 | failed:(WTRequestFailedBlock)failed; 169 | 170 | #pragma mark - 其他 171 | /*! 172 | shared Call Back Queue 173 | */ 174 | +(NSOperationQueue*)sharedQueue; 175 | /*! 176 | shared Cache 177 | */ 178 | +(NSURLCache*)sharedCache; 179 | 180 | /*! 181 | Clears the receiver’s cache, removing all stored cached URL responses. 182 | */ 183 | +(void)clearAllCache; 184 | 185 | 186 | /*! 187 | @method currentDiskUsage 188 | current Disk Usage 189 | */ 190 | 191 | +(NSUInteger)currentDiskUsage; 192 | 193 | //当前缓存用量,直接根据大小来调节单位的显示,KB,MB,GB,TB,PB,EB 194 | +(NSString*)currentDiskUsageString; 195 | 196 | 197 | /*! 198 | 根据请求清除被保存的的缓存 199 | Removes the NSCachedURLResponse from the cache that is 200 | stored using the given request. 201 | */ 202 | +(void)removeRequestCache:(NSURLRequest*)request; 203 | 204 | 205 | #pragma mark - 辅助 206 | //JSON转对象 207 | +(id)JSONObjectWithData:(NSData*)data; 208 | +(NSString*)stringWithData:(NSObject*)data; 209 | 210 | //JSON对象转data 211 | +(NSData*)dataFromJSONObject:(id)object; 212 | #pragma mark - URL 213 | //根路径 214 | +(NSString *)baseURL; 215 | //实际应用示例 216 | +(NSString*)URLWithIndex:(NSInteger)index; 217 | 218 | 219 | 220 | #pragma mark - Testing Method 221 | 222 | +(WTURLRequestOperation*)testdoURLRequest:(NSURLRequest*)request 223 | progress:(WTDownLoadProgressBlock)progress 224 | finished:(WTRequestFinishedBlock)finished 225 | failed:(WTRequestFailedBlock)failed; 226 | 227 | /*! 228 | 普通的GET方法 229 | */ 230 | +(WTURLRequestOperation*)testGetWithURL:(NSString *)url 231 | parameters:(NSDictionary *)parameters 232 | finished:(WTRequestFinishedBlock)finished 233 | failed:(WTRequestFailedBlock)failed; 234 | 235 | /*! 236 | 带缓存策略的GET请求 237 | */ 238 | +(WTURLRequestOperation*)testGetWithURL:(NSString*)url 239 | parameters:(NSDictionary *)parameters 240 | option:(WTRequestCenterCachePolicy)option 241 | finished:(WTRequestFinishedBlock)finished 242 | failed:(WTRequestFailedBlock)failed; 243 | 244 | /*! 245 | 测试中的GET方法,传入URL和参数以后 246 | 给出option,可以得知下载的进程, 247 | 还有成功和失败的回调 248 | 249 | */ 250 | +(WTURLRequestOperation*)testGetWithURL:(NSString*)url 251 | parameters:(NSDictionary *)parameters 252 | option:(WTRequestCenterCachePolicy)option 253 | progress:(WTDownLoadProgressBlock)progress 254 | finished:(WTRequestFinishedBlock)finished 255 | failed:(WTRequestFailedBlock)failed; 256 | 257 | /*! 258 | POST方法,加入runloop中 259 | */ 260 | +(WTURLRequestOperation*)testPOSTWithURL:(NSString*)url 261 | parameters:(NSDictionary *)parameters 262 | finished:(WTRequestFinishedBlock)finished 263 | failed:(WTRequestFailedBlock)failed; 264 | @end 265 | 266 | ///-------------------- 267 | /// @name Notifications 268 | ///-------------------- 269 | 270 | 271 | /** 272 | Posted when an operation begins executing. 273 | */ 274 | extern NSString * const WTNetworkingOperationDidStartNotification; 275 | 276 | /** 277 | Posted when an operation finishes. 278 | */ 279 | extern NSString * const WTNetworkingOperationDidFinishNotification; 280 | 281 | 282 | /*! 283 | Debug模式 284 | */ 285 | extern BOOL const WTRequestCenterDebugMode; 286 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/WTRequestCenter/WTURLRequestOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // WTURLRequestOperation.h 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-8-29. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | /* 9 | 这是一个方便的缓存式网络请求的缓存库,在网络不好 10 | 或者没有网络的情况下方便读取缓存来看。 11 | 12 | 使用方法很简单,只需要传URL和参数就可以了。 13 | 14 | 还提供上传图片功能,下载图片功能,缓存图片功能 15 | 还有JSON解析功能,还提供来一个URL的表让你来填写 16 | 然后直接快捷取URL。 17 | 希望能帮到你,谢谢。 18 | 如果有任何问题可以在github上向我提出 19 | Mike 20 | 21 | */ 22 | #import 23 | typedef void (^WTRequestComplectionBlock)(NSURLResponse *response,NSData *data,NSError *error); 24 | typedef void(^WTDownLoadProgressBlock)(NSUInteger bytesRead,long long totalBytesRead,long long totalBytesExpectedToRead); 25 | 26 | 27 | 28 | 29 | 30 | @interface WTURLRequestOperation : NSOperation 31 | { 32 | NSURLConnection *wtURLConnection; 33 | 34 | 35 | } 36 | 37 | @property (readwrite, nonatomic, copy) WTDownLoadProgressBlock downloadProgress; 38 | 39 | -(instancetype)initWithRequest:(NSURLRequest*)request; 40 | -(void)setCompletionHandler:(WTRequestComplectionBlock)handler; 41 | 42 | 43 | 44 | @property (nonatomic, strong) NSSet *runLoopModes; 45 | 46 | @property (nonatomic,retain) NSMutableData *responseData; 47 | @property (nonatomic,retain,readonly)NSURLRequest *request; 48 | @property (nonatomic,retain,readonly)NSURLResponse *response; 49 | @property (nonatomic,retain)NSError *error; 50 | @end 51 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/WTRequestCenter/WTURLRequestOperation.m: -------------------------------------------------------------------------------- 1 | // 2 | // WTURLRequestOperation.m 3 | // WTRequestCenter 4 | // 5 | // Created by songwt on 14-8-29. 6 | // Copyright (c) 2014年 song. All rights reserved. 7 | // 8 | 9 | #import "WTURLRequestOperation.h" 10 | #import "WTRequestCenter.h" 11 | 12 | 13 | 14 | 15 | //operation 状态 16 | typedef NS_ENUM(NSInteger, WTOperationState){ 17 | WTOperationStatePause, 18 | WTOperationStateReady, 19 | WTOperationStateExecuting, 20 | WTOperationStateFinished 21 | }; 22 | 23 | 24 | static inline NSString * WTKeyPathFromOperationState(WTOperationState state) { 25 | switch (state) { 26 | case WTOperationStatePause: 27 | { 28 | return @"isPaused"; 29 | } 30 | break; 31 | case WTOperationStateReady: 32 | { 33 | return @"isReady"; 34 | } 35 | break; 36 | case WTOperationStateExecuting: 37 | { 38 | return @"isExecuting"; 39 | } 40 | break; 41 | case WTOperationStateFinished: 42 | { 43 | return @"isFinished"; 44 | } 45 | break; 46 | default: 47 | return @"state"; 48 | break; 49 | } 50 | 51 | } 52 | 53 | 54 | @interface WTURLRequestOperation() 55 | 56 | //Operation状态 57 | @property (readwrite, nonatomic, assign) WTOperationState state; 58 | 59 | //锁 60 | @property (readwrite, nonatomic, strong) NSRecursiveLock *lock; 61 | 62 | @property (nonatomic,retain,readwrite)NSURLRequest *request; 63 | @property (nonatomic,retain,readwrite)NSURLResponse *response; 64 | @end 65 | @implementation WTURLRequestOperation 66 | 67 | - (instancetype)initWithRequest:(NSURLRequest*)request 68 | { 69 | self = [super init]; 70 | if (self) { 71 | self.request = request; 72 | self.lock = [[NSRecursiveLock alloc] init]; 73 | self.lock.name = @"WTRequestCenter.WTURLRequestOperation.lock"; 74 | 75 | _state = WTOperationStateReady; 76 | 77 | 78 | self.runLoopModes = [NSSet setWithObject:NSRunLoopCommonModes]; 79 | } 80 | return self; 81 | } 82 | 83 | -(void)setCompletionHandler:(void (^)(NSURLResponse* response,NSData *data,NSError *error))handler 84 | { 85 | #pragma clang diagnostic push 86 | #pragma clang diagnostic ignored "-Warc-retain-cycles" 87 | #pragma clang diagnostic ignored "-Wgnu" 88 | [self.lock lock]; 89 | [self setCompletionBlock:^{ 90 | 91 | if (!self.error) { 92 | // 如果请求无误 93 | NSCachedURLResponse *res = [[NSCachedURLResponse alloc] initWithResponse:self.response data:self.responseData]; 94 | [[WTRequestCenter sharedCache] storeCachedResponse:res forRequest:self.request]; 95 | } 96 | if (handler) { 97 | dispatch_async(dispatch_get_main_queue(), ^{ 98 | handler(self.response,self.responseData,self.error); 99 | }); 100 | } 101 | }]; 102 | [self.lock unlock]; 103 | #pragma clang diagnostic pop 104 | } 105 | 106 | 107 | 108 | -(BOOL)isConcurrent 109 | { 110 | return YES; 111 | } 112 | -(BOOL)isReady 113 | { 114 | return self.state == WTOperationStateReady; 115 | } 116 | 117 | -(BOOL)isExecuting 118 | { 119 | return self.state == WTOperationStateExecuting; 120 | } 121 | 122 | -(BOOL)isFinished 123 | { 124 | return self.state == WTOperationStateFinished; 125 | } 126 | 127 | 128 | 129 | -(void)start 130 | { 131 | [self.lock lock]; 132 | if (![self isCancelled]) { 133 | if([self isReady]) 134 | { 135 | self.state = WTOperationStateExecuting; 136 | [self performSelector:@selector(operationDidStart) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]]; 137 | } 138 | } 139 | 140 | [self.lock unlock]; 141 | } 142 | 143 | - (void)setState:(WTOperationState)state { 144 | [self.lock lock]; 145 | NSString *oldStateKey = WTKeyPathFromOperationState(self.state); 146 | NSString *newStateKey = WTKeyPathFromOperationState(state); 147 | [self willChangeValueForKey:oldStateKey]; 148 | [self willChangeValueForKey:newStateKey]; 149 | 150 | _state = state; 151 | [self didChangeValueForKey:oldStateKey]; 152 | [self didChangeValueForKey:newStateKey]; 153 | 154 | 155 | [self.lock unlock]; 156 | } 157 | 158 | 159 | 160 | //网络访问线程 161 | + (NSThread *)networkRequestThread { 162 | static NSThread *_networkRequestThread = nil; 163 | static dispatch_once_t oncePredicate; 164 | dispatch_once(&oncePredicate, ^{ 165 | _networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil]; 166 | [_networkRequestThread start]; 167 | }); 168 | 169 | return _networkRequestThread; 170 | } 171 | 172 | + (void)networkRequestThreadEntryPoint:(id)__unused object { 173 | @autoreleasepool { 174 | [[NSThread currentThread] setName:@"WTRequestCenter"]; 175 | 176 | NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; 177 | [runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode]; 178 | [runLoop run]; 179 | } 180 | } 181 | 182 | 183 | - (void)operationDidStart 184 | { 185 | [self.lock lock]; 186 | wtURLConnection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO]; 187 | 188 | NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; 189 | [self.runLoopModes enumerateObjectsUsingBlock:^(NSString *runLoopMode, BOOL *stop) { 190 | [wtURLConnection scheduleInRunLoop:runLoop forMode:runLoopMode]; 191 | }]; 192 | [wtURLConnection start]; 193 | 194 | dispatch_async(dispatch_get_main_queue(), ^{ 195 | NSDictionary *userInfo = @{@"request": _request}; 196 | [[NSNotificationCenter defaultCenter] postNotificationName:WTNetworkingOperationDidStartNotification object:_request userInfo:userInfo]; 197 | }); 198 | [self.lock unlock]; 199 | } 200 | - (void)cancel 201 | { 202 | [self.lock lock]; 203 | if (![self isFinished] && ![self isCancelled]) { 204 | [super cancel]; 205 | if ([self isExecuting]) { 206 | [self performSelector:@selector(cancelConnection) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]]; 207 | 208 | } 209 | } 210 | [self.lock unlock]; 211 | } 212 | 213 | - (void)cancelConnection { 214 | NSDictionary *userInfo = nil; 215 | if ([self.request URL]) { 216 | userInfo = @{NSURLErrorFailingURLErrorKey: [self.request URL]}; 217 | } 218 | NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]; 219 | 220 | if (![self isFinished]) { 221 | if (wtURLConnection) { 222 | [wtURLConnection cancel]; 223 | [self performSelector:@selector(connection:didFailWithError:) withObject:wtURLConnection withObject:error]; 224 | 225 | }else 226 | { 227 | self.error = error; 228 | [self finish]; 229 | } 230 | } 231 | } 232 | 233 | - (void)finish { 234 | [self.lock lock]; 235 | self.state = WTOperationStateFinished; 236 | 237 | dispatch_async(dispatch_get_main_queue(), ^{ 238 | NSDictionary *userInfo = @{@"request": _request}; 239 | [[NSNotificationCenter defaultCenter] postNotificationName:WTNetworkingOperationDidFinishNotification object:_request userInfo:userInfo]; 240 | }); 241 | 242 | [self.lock unlock]; 243 | 244 | } 245 | #pragma mark - NSURLConnectionDataDelegate 246 | - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 247 | { 248 | self.responseData = [[NSMutableData alloc] init]; 249 | self.response = response; 250 | } 251 | 252 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 253 | { 254 | [_responseData appendData:data]; 255 | if (_downloadProgress) { 256 | dispatch_async(dispatch_get_main_queue(), ^{ 257 | _downloadProgress([data length],[_responseData length],_response.expectedContentLength); 258 | }); 259 | } 260 | 261 | } 262 | 263 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection 264 | { 265 | wtURLConnection = nil; 266 | [self finish]; 267 | } 268 | 269 | #pragma mark - NSURLConnectionDelegate 270 | - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 271 | { 272 | self.error = error; 273 | wtURLConnection = nil; 274 | [self finish]; 275 | } 276 | 277 | @end 278 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/WTRequestCenter/WTURLRequestSerialization.h: -------------------------------------------------------------------------------- 1 | // 2 | // WTURLRequestSerialization.h 3 | // WTRequestCenter 4 | // 5 | // Created by SongWentong on 14/11/24. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | /* 9 | 这是一个方便的缓存式网络请求的缓存库,在网络不好 10 | 或者没有网络的情况下方便读取缓存来看。 11 | 12 | 使用方法很简单,只需要传URL和参数就可以了。 13 | 14 | 还提供上传图片功能,下载图片功能,缓存图片功能 15 | 还有JSON解析功能,还提供来一个URL的表让你来填写 16 | 然后直接快捷取URL。 17 | 希望能帮到你,谢谢。 18 | 如果有任何问题可以在github上向我提出 19 | Mike 20 | 21 | */ 22 | #import 23 | @protocol WTMultipartFormData; 24 | extern NSTimeInterval const WTURLRequestSerializationTimeoutTimeInterval; 25 | 26 | @interface WTURLRequestSerialization : NSObject 27 | //单例 28 | +(instancetype)sharedRequestSerialization; 29 | //超时时长 30 | @property (nonatomic) NSTimeInterval timeoutInterval; 31 | 32 | //获得请求头 33 | - (NSString *)valueForHTTPHeaderField:(NSString *)field; 34 | 35 | //设置请求头 36 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field; 37 | 38 | /*! 39 | 40 | GET请求 41 | */ 42 | 43 | //实例的GET方法 44 | -(NSMutableURLRequest*)GETRequestWithURL:(NSString*)url 45 | parameters:(NSDictionary*)parameters; 46 | 47 | /*! 48 | 49 | POST请求 50 | */ 51 | 52 | //实例的POST方法 53 | -(NSMutableURLRequest*)POSTRequestWithURL:(NSString*)url 54 | parameters:(NSDictionary*)parameters; 55 | 56 | /*! 57 | 58 | 支持数据上传的POST请求 59 | */ 60 | 61 | -(NSMutableURLRequest*)POSTRequestWithURL:(NSString*)url 62 | parameters:(NSDictionary*)parameters 63 | constructingBodyWithBlock:(void (^)(id formData))block; 64 | 65 | 66 | 67 | /*! 68 | PUT请求 69 | */ 70 | -(NSMutableURLRequest*)PUTRequestWithURL:(NSString*)url 71 | parameters:(NSDictionary*)parameters; 72 | 73 | 74 | /*! 75 | DELETE 请求 76 | */ 77 | -(NSMutableURLRequest*)DELETERequestWithURL:(NSString*)url 78 | parameters:(NSDictionary*)parameters; 79 | 80 | /*! 81 | HEAD 请求 82 | */ 83 | -(NSMutableURLRequest*)HEADRequestWithURL:(NSString*)url 84 | parameters:(NSDictionary*)parameters; 85 | 86 | 87 | 88 | 89 | 90 | #pragma mark - 其他 91 | 92 | /*! 93 | 根据给出的HTTP响应取到响应时间 94 | */ 95 | +(NSDate*)dateFromHTTPURLResponse:(NSHTTPURLResponse*)response; 96 | 97 | 98 | @end 99 | @protocol WTMultipartFormData 100 | 101 | /*! 102 | 暂未完成 103 | */ 104 | - (BOOL)appendPartWithFileURL:(NSURL *)fileURL 105 | name:(NSString *)name 106 | error:(NSError * __autoreleasing *)error; 107 | 108 | /*! 109 | 数据上传协议 110 | */ 111 | - (BOOL)appendPartWithData:(NSData*)data 112 | name:(NSString*)name; 113 | @end 114 | 115 | @interface WTJSONRequestSerialization : WTURLRequestSerialization 116 | //加上JSON请求 117 | - (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request 118 | withParameters:(id)parameters 119 | error:(NSError *__autoreleasing *)error; 120 | @end 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /AutolayoutDemo/Library/WTRequestCenter/WTURLSessionManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // WTURLSessionManager.h 3 | // WTRequestCenter 4 | // 5 | // Created by song on 14-8-1. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | /* 9 | 这是一个方便的缓存式网络请求的缓存库,在网络不好 10 | 或者没有网络的情况下方便读取缓存来看。 11 | 12 | 使用方法很简单,只需要传URL和参数就可以了。 13 | 14 | 还提供上传图片功能,下载图片功能,缓存图片功能 15 | 还有JSON解析功能,还提供来一个URL的表让你来填写 16 | 然后直接快捷取URL。 17 | 希望能帮到你,谢谢。 18 | 如果有任何问题可以在github上向我提出 19 | Mike 20 | 21 | */ 22 | 23 | #import 24 | //#import "WTRequestCenter.h" 25 | #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) 26 | @interface WTURLSessionManager : NSObject 27 | 28 | //默认的session管理器 29 | +(WTURLSessionManager*)sharedManager; 30 | 31 | @property (readonly,nonatomic,strong) NSURLSession *URLSession; 32 | @property (readonly,nonatomic,strong) NSURLSessionConfiguration *sessionConfiguration; 33 | 34 | - (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration; 35 | 36 | #pragma mark - Adding Data Tasks to a Session 37 | - (NSURLSessionDataTask *)dataTaskWithURL:(NSURL *)url 38 | completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler; 39 | - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request 40 | completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler; 41 | 42 | 43 | #pragma mark - Adding Download Tasks to a Session 44 | - (NSURLSessionDownloadTask *)downloadTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler; 45 | 46 | - (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler; 47 | 48 | - (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler; 49 | 50 | 51 | #pragma mark - Adding Upload Tasks to a Session 52 | - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromData:(NSData *)bodyData completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler; 53 | 54 | - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler; 55 | @end 56 | #endif -------------------------------------------------------------------------------- /AutolayoutDemo/Library/WTRequestCenter/WTURLSessionManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // WTURLSessionManager.m 3 | // WTRequestCenter 4 | // 5 | // Created by song on 14-8-1. 6 | // Copyright (c) Mike song(mailto:275712575@qq.com). All rights reserved. 7 | // site:https://github.com/swtlovewtt/WTRequestCenter 8 | 9 | #import "WTURLSessionManager.h" 10 | #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) 11 | @interface WTURLSessionManager() 12 | @property (readwrite, nonatomic, strong) NSURLSessionConfiguration *sessionConfiguration; 13 | @property (nonatomic,retain) NSOperationQueue *operationQueue; 14 | 15 | @property (nonatomic,strong) NSURLSession *URLSession; 16 | @end 17 | @implementation WTURLSessionManager 18 | 19 | 20 | static WTURLSessionManager *sharedSessionManager; 21 | +(WTURLSessionManager*)sharedManager 22 | { 23 | static dispatch_once_t onceToken; 24 | dispatch_once(&onceToken, ^{ 25 | sharedSessionManager = [[WTURLSessionManager alloc] initWithSessionConfiguration:nil]; 26 | 27 | }); 28 | 29 | return sharedSessionManager; 30 | } 31 | - (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration { 32 | self = [super init]; 33 | if (self) { 34 | 35 | if (!configuration) { 36 | configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; 37 | } 38 | self.sessionConfiguration = configuration; 39 | self.operationQueue = [[NSOperationQueue alloc] init]; 40 | self.URLSession = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:_operationQueue]; 41 | [_operationQueue setSuspended:NO]; 42 | } 43 | return self; 44 | } 45 | #pragma mark - Adding Data Tasks to a Session 46 | 47 | - (NSURLSessionDataTask *)dataTaskWithURL:(NSURL *)url 48 | completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler{ 49 | NSURLSessionDataTask *task = nil; 50 | NSURLRequest *request = [NSURLRequest requestWithURL:url]; 51 | [_URLSession dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 52 | if (completionHandler) { 53 | completionHandler(data,response,error); 54 | } 55 | }]; 56 | 57 | return task; 58 | } 59 | - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request 60 | completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler{ 61 | NSURLSessionDataTask *task = nil; 62 | [_URLSession dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 63 | if (completionHandler) { 64 | completionHandler(data,response,error); 65 | } 66 | }]; 67 | 68 | return task; 69 | } 70 | 71 | #pragma mark - Adding Download Tasks to a Session 72 | - (NSURLSessionDownloadTask *)downloadTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler{ 73 | 74 | NSURLRequest *request = [NSURLRequest requestWithURL:url]; 75 | NSURLSessionDownloadTask *task = nil; 76 | [_URLSession downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) { 77 | if (completionHandler) { 78 | completionHandler(location,response,error); 79 | } 80 | }]; 81 | return task; 82 | } 83 | 84 | 85 | - (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler{ 86 | NSURLSessionDownloadTask *task = nil; 87 | [_URLSession downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) { 88 | if (completionHandler) { 89 | completionHandler(location,response,error); 90 | } 91 | }]; 92 | return task; 93 | } 94 | 95 | 96 | - (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData completionHandler:(void (^)(NSURL *location, NSURLResponse *response, NSError *error))completionHandler 97 | { 98 | NSURLSessionDownloadTask *task = nil; 99 | [_URLSession downloadTaskWithResumeData:resumeData completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) { 100 | if (completionHandler) { 101 | completionHandler(location,response,error); 102 | } 103 | }]; 104 | return task; 105 | } 106 | 107 | #pragma mark - Adding Upload Tasks to a Session 108 | - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromData:(NSData *)bodyData completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler 109 | { 110 | NSURLSessionUploadTask *task = nil; 111 | [_URLSession uploadTaskWithRequest:request fromData:bodyData completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 112 | if (completionHandler) { 113 | completionHandler(data,response,error); 114 | } 115 | }]; 116 | return task; 117 | } 118 | 119 | - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler 120 | { 121 | NSURLSessionUploadTask *task = nil; 122 | [_URLSession uploadTaskWithRequest:request fromFile:fileURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 123 | if (completionHandler) { 124 | completionHandler(data,response,error); 125 | } 126 | }]; 127 | return task; 128 | } 129 | 130 | #pragma mark - Just a joke 131 | - (NSString *)debugDescription 132 | { 133 | return @"just a joke"; 134 | } 135 | 136 | @end 137 | #endif -------------------------------------------------------------------------------- /AutolayoutDemo/Model/NewsCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // NewsCenter.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NewsCenter : NSObject 12 | 13 | 14 | //保存本地新闻栏目列表 15 | +(void)saveLocalNewsColumn:(NSArray*)array; 16 | //获取本地新闻栏目列表 17 | +(void)localNewsColumnWithComplection:(void(^)(NSArray *array))completion; 18 | 19 | 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /AutolayoutDemo/Model/NewsCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // NewsCenter.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NewsCenter.h" 10 | #import "WTNetWork.h" 11 | #import "UIKit+WTRequestCenter.h" 12 | @implementation NewsCenter 13 | 14 | 15 | static NSString *localColumnName = @"NewsCenter local column name"; 16 | 17 | +(void)saveLocalNewsColumn:(NSArray*)array 18 | { 19 | assert(!array); 20 | [WTDataSaver saveData:[NSJSONSerialization dataWithJSONObject:array options:0 error:nil] withName:localColumnName]; 21 | } 22 | 23 | +(void)localNewsColumnWithComplection:(void(^)(NSArray *array))completion 24 | { 25 | // NSArray *result = nil; 26 | [WTDataSaver dataWithName:localColumnName 27 | completion:^(NSData *data) { 28 | 29 | NSArray *array = [WTRequestCenter JSONObjectWithData:data]; 30 | 31 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 32 | if (completion) { 33 | completion(array); 34 | } 35 | }]; 36 | 37 | }]; 38 | 39 | 40 | } 41 | 42 | 43 | //获取新闻的分类 44 | +(void)getNewsCategoty 45 | { 46 | 47 | 48 | //http://c.m.163.com/nc/topicset/ios/v4/subscribe/news/all.html 49 | [WTRequestCenter getWithURL:@"http://c.m.163.com/nc/topicset/ios/v4/subscribe/news/all.html" 50 | parameters:nil 51 | option:WTRequestCenterCachePolicyNormal 52 | finished:^(NSURLResponse *response, NSData *data) { 53 | NSDictionary *dict = [WTRequestCenter JSONObjectWithData:data]; 54 | NSLog(@"当前新闻分类 %@",dict); 55 | } failed:^(NSURLResponse *response, NSError *error) { 56 | 57 | }]; 58 | } 59 | @end 60 | 61 | 62 | 63 | /* 64 | // 图集的新闻接口 65 | http://c.m.163.com/photo/api/set/0096/55411.json 66 | 67 | http://c.m.163.com/photo/api/set/0096/55494.json 68 | */ 69 | 70 | 71 | /* 72 | 这是热门评论 73 | http://comment.api.163.com/api/json/post/list/new/hot/3g_bbs/AF661E1900963VRO/0/10/10/2/2 74 | 75 | 76 | 这个是正常的评论 0-9 77 | http://comment.api.163.com/api/json/post/list/new/normal/3g_bbs/AF661E1900963VRO/desc/0/10/10/2/2 78 | 79 | 分页这是 10-19 80 | http://comment.api.163.com/api/json/post/list/new/normal/3g_bbs/AF661E1900963VRO/desc/10/10/10/2/2 81 | 82 | 这是 20-29 83 | http://comment.api.163.com/api/json/post/list/new/normal/3g_bbs/AF661E1900963VRO/desc/20/10/10/2/2 84 | 85 | 30-39 86 | http://comment.api.163.com/api/json/post/list/new/normal/3g_bbs/AF661E1900963VRO/desc/30/10/10/2/2 87 | */ 88 | -------------------------------------------------------------------------------- /AutolayoutDemo/Resource/Font/DS-DIGI.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Resource/Font/DS-DIGI.TTF -------------------------------------------------------------------------------- /AutolayoutDemo/Resource/Font/DS-DIGIB.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Resource/Font/DS-DIGIB.TTF -------------------------------------------------------------------------------- /AutolayoutDemo/Resource/Font/StencilStd.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Resource/Font/StencilStd.ttf -------------------------------------------------------------------------------- /AutolayoutDemo/Resource/Font/lijinheiW8.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ChinaiOSDeveloper/EasyNews/fb32b5ffa31f7fd14906d5e608ed11b65eefd2d6/AutolayoutDemo/Resource/Font/lijinheiW8.TTF -------------------------------------------------------------------------------- /AutolayoutDemo/SecondViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SecondViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /AutolayoutDemo/SecondViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SecondViewController.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "SecondViewController.h" 10 | 11 | @interface SecondViewController () 12 | 13 | @end 14 | 15 | @implementation SecondViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | - (void)didReceiveMemoryWarning { 23 | [super didReceiveMemoryWarning]; 24 | // Dispose of any resources that can be recreated. 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/AtlasViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AtlasViewController.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/10. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NewsDetailViewController.h" 10 | //图集形式 11 | @interface AtlasViewController : NewsDetailViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/AtlasViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // AtlasViewController.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/10. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "AtlasViewController.h" 10 | #import "NewsImageCollectionViewCell.h" 11 | #import "UIKit+WTRequestCenter.h" 12 | @interface AtlasViewController () 13 | { 14 | 15 | } 16 | 17 | @property (strong, nonatomic) IBOutlet UICollectionView *myCollectionView; 18 | @property (strong, nonatomic) IBOutlet UICollectionViewFlowLayout *myCollectionViewFlowLayout; 19 | @property (strong, nonatomic) NSArray *photos; 20 | @end 21 | 22 | @implementation AtlasViewController 23 | 24 | - (void)viewDidLoad { 25 | [super viewDidLoad]; 26 | // Do any additional setup after loading the view from its nib. 27 | _myCollectionViewFlowLayout.itemSize = self.view.bounds.size; 28 | // _myCollectionViewFlowLayout.minimumInteritemSpacing = 0; 29 | // _myCollectionViewFlowLayout.minimumLineSpacing = 0; 30 | // _myCollectionViewFlowLayout.itemSize = CGSizeMake(320, 400); 31 | 32 | 33 | UINib *nib = [UINib nibWithNibName:@"NewsImageCollectionViewCell" 34 | bundle:nil]; 35 | [self.myCollectionView registerNib:nib 36 | forCellWithReuseIdentifier:@"NewsImageCollectionViewCell"]; 37 | 38 | } 39 | 40 | - (void)didReceiveMemoryWarning { 41 | [super didReceiveMemoryWarning]; 42 | // Dispose of any resources that can be recreated. 43 | } 44 | 45 | 46 | -(void)useData 47 | { 48 | [super useData]; 49 | 50 | NSArray *photos = [self.newsData valueForKey:@"photos"]; 51 | self.photos = photos; 52 | [_myCollectionView reloadData]; 53 | } 54 | 55 | #pragma mark - UICollectionViewDataSource 56 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 57 | { 58 | return _photos.count; 59 | } 60 | 61 | // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: 62 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 63 | { 64 | UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NewsImageCollectionViewCell" 65 | forIndexPath:indexPath]; 66 | NewsImageCollectionViewCell *temp = (NewsImageCollectionViewCell*)cell; 67 | temp.imageInfo = _photos[indexPath.row]; 68 | NSString *imgurl = [temp.imageInfo valueForKey:@"imgurl"]; 69 | [temp.newsImageView setImageWithURL:imgurl]; 70 | return cell; 71 | } 72 | 73 | #pragma mark - UICollectionViewDelegate 74 | 75 | #pragma mark - UICollectionViewDelegateFlowLayout 76 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 77 | { 78 | CGSize size = CGSizeZero; 79 | size = self.view.bounds.size; 80 | // size = collectionView.bounds.size; 81 | // size = CGSizeMake(300, 300); 82 | return size; 83 | } 84 | 85 | /* 86 | #pragma mark - Navigation 87 | 88 | // In a storyboard-based application, you will often want to do a little preparation before navigation 89 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 90 | // Get the new view controller using [segue destinationViewController]. 91 | // Pass the selected object to the new view controller. 92 | } 93 | */ 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/AtlasViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/CommentCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // CommentCell.h 3 | // AutolayoutDemo 4 | // 5 | // Created by 孙 化育 on 15-1-7. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width 12 | @interface CommentCell : UITableViewCell 13 | 14 | @property (weak, nonatomic) IBOutlet UIImageView *headImageView; 15 | @property (weak, nonatomic) IBOutlet UILabel *nameLabel; 16 | @property (weak, nonatomic) IBOutlet UILabel *addressLabel; 17 | @property (weak, nonatomic) IBOutlet UILabel *commentCountLabel; 18 | @property (weak, nonatomic) IBOutlet UIButton *zanButton; 19 | 20 | - (void)setContentWithData:(NSDictionary *)dic; 21 | 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/CommentCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // CommentCell.m 3 | // AutolayoutDemo 4 | // 5 | // Created by 孙 化育 on 15-1-7. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "CommentCell.h" 10 | #import "UIKit+WTRequestCenter.h" 11 | 12 | 13 | 14 | 15 | @implementation CommentCell 16 | 17 | - (void)awakeFromNib { 18 | // Initialization code 19 | self.headImageView.layer.cornerRadius = 25; 20 | self.headImageView.layer.masksToBounds = YES; 21 | self.selectionStyle = UITableViewCellSelectionStyleNone; 22 | } 23 | 24 | 25 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 26 | [super setSelected:selected animated:animated]; 27 | 28 | // Configure the view for the selected state 29 | } 30 | 31 | - (void)setContentWithData:(NSDictionary *)dic{ 32 | for (UIView *view in [self.contentView subviews]) { 33 | if (view.tag>0) { 34 | [view removeFromSuperview]; 35 | } 36 | } 37 | NSArray *comArr = [dic allValues]; 38 | int commentLabelY = 66+(int)(comArr.count-1)*3; 39 | int firstLabelY = 66+(int)(comArr.count-1)*3; 40 | for (int i = 0; i1) { 45 | //回复 46 | int thisWidth = SCREEN_WIDTH-16-6*(comArr.count-i-1); 47 | int thisXPoint = 8+3*((int)comArr.count-i-1); 48 | CGRect rect = [commentText boundingRectWithSize:CGSizeMake(thisWidth, 0) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil]; 49 | UIView *view = [[UIView alloc] initWithFrame:CGRectMake(thisXPoint, firstLabelY, thisWidth, rect.size.height+20+commentLabelY-66)]; 50 | view.layer.borderColor = [[UIColor blackColor] CGColor]; 51 | view.layer.borderWidth = 1; 52 | view.tag = 11; 53 | view.backgroundColor = [UIColor yellowColor]; 54 | 55 | UILabel *replyNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, commentLabelY-66, view.frame.size.width, 20)]; 56 | replyNameLabel.textColor = [UIColor blueColor]; 57 | replyNameLabel.text = [comment objectForKey:@"n"]?[comment objectForKey:@"n"]:@"火影网友"; 58 | replyNameLabel.backgroundColor = [UIColor clearColor]; 59 | [view addSubview:replyNameLabel]; 60 | 61 | UILabel *replyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20+commentLabelY-66, view.frame.size.width, rect.size.height)]; 62 | replyLabel.numberOfLines = 0; 63 | replyLabel.font = [UIFont systemFontOfSize:16]; 64 | replyLabel.text = [NSString stringWithFormat:@"%@",commentText]; 65 | replyLabel.backgroundColor = [UIColor clearColor]; 66 | [view addSubview:replyLabel]; 67 | [self.contentView addSubview:view]; 68 | [self.contentView sendSubviewToBack:view]; 69 | commentLabelY = commentLabelY+rect.size.height+3+20; 70 | firstLabelY -= 3; 71 | }else{ 72 | //评论 73 | CGRect rect = [commentText boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-16, 0) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil]; 74 | 75 | UILabel *commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, commentLabelY, SCREEN_WIDTH-16, rect.size.height)]; 76 | commentLabel.numberOfLines = 0; 77 | commentLabel.tag = 10; 78 | commentLabel.font = [UIFont systemFontOfSize:16]; 79 | commentLabel.text = commentText; 80 | [self.contentView addSubview:commentLabel]; 81 | if ([comment objectForKey:@"timg"]&&![[comment objectForKey:@"timg"] isEqual:[NSNull null]]) { 82 | [self.headImageView setImageWithURL:[comment objectForKey:@"timg"]]; 83 | }else{ 84 | self.headImageView.image = [UIImage imageNamed:@"comment_profile_mars"]; 85 | } 86 | self.nameLabel.text = [comment objectForKey:@"n"]?[comment objectForKey:@"n"]:@"火影网友"; 87 | self.addressLabel.text = [[[comment objectForKey:@"f"] componentsSeparatedByString:@" "] firstObject]; 88 | self.commentCountLabel.text = [comment objectForKey:@"v"]; 89 | } 90 | } 91 | 92 | 93 | 94 | } 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/CommentCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 32 | 38 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/CommentVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // CommentVC.h 3 | // AutolayoutDemo 4 | // 5 | // Created by 孙 化育 on 15-1-6. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CommentVC : UIViewController 12 | 13 | @property (nonatomic,strong) NSDictionary *articleInfo; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/CommentVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // CommentVC.m 3 | // AutolayoutDemo 4 | // 5 | // Created by 孙 化育 on 15-1-6. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "CommentVC.h" 10 | #import "WTRequestCenter.h" 11 | #import "CommentCell.h" 12 | 13 | @interface CommentVC (){ 14 | 15 | __weak IBOutlet UITableView *_table; 16 | } 17 | 18 | @property (nonatomic,strong)NSArray *hotCommentsArray; 19 | 20 | @end 21 | 22 | @implementation CommentVC 23 | 24 | 25 | #pragma mark- view 26 | - (void)viewDidLoad { 27 | [super viewDidLoad]; 28 | 29 | [_table registerNib:[UINib nibWithNibName:@"CommentCell" bundle:nil] forCellReuseIdentifier:@"comment"]; 30 | //NSLog(@"%@",_articleInfo); 31 | //NSLog(@"%@",[_articleInfo objectForKey:@"source"]); 32 | //请求数据,先尝试从news_guonei8_bbs请求; 33 | NSString *urlString = [NSString stringWithFormat:@"http://comment.api.163.com/api/json/post/list/new/hot/news_guonei8_bbs/%@/0/10/10/2/2",[_articleInfo objectForKey:@"docid"]]; 34 | //NSLog(@"%@",urlString); 35 | [WTRequestCenter getWithURL:urlString parameters:nil finished:^(NSURLResponse *response, NSData *data) { 36 | NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 37 | NSDictionary *dic = [WTRequestCenter JSONObjectWithData:data]; 38 | NSLog(@"---%@",str); 39 | if ([[dic objectForKey:@"code"] intValue] == -5) { 40 | //如果没有数据再从3g_bbs请求数据 41 | NSString *secUrl = [NSString stringWithFormat:@"http://comment.api.163.com/api/json/post/list/new/hot/3g_bbs/%@/0/10/10/2/2",[_articleInfo objectForKey:@"docid"]]; 42 | [WTRequestCenter getWithURL:secUrl parameters:nil finished:^(NSURLResponse *response, NSData *data) { 43 | NSDictionary *secDic = [WTRequestCenter JSONObjectWithData:data]; 44 | self.hotCommentsArray = [secDic objectForKey:@"hotPosts"]; 45 | if ([_hotCommentsArray isEqual:[NSNull null]]) { 46 | 47 | }else 48 | { 49 | NSString *secStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 50 | NSLog(@"---%@",secStr); 51 | [_table reloadData]; 52 | } 53 | 54 | } failed:^(NSURLResponse *response, NSError *error) { 55 | NSLog(@"请求失败%@",error.localizedDescription); 56 | }]; 57 | }else{ 58 | self.hotCommentsArray = [dic objectForKey:@"hotPosts"]; 59 | [_table reloadData]; 60 | } 61 | } failed:^(NSURLResponse *response, NSError *error) { 62 | NSLog(@"请求失败%@",error.localizedDescription); 63 | }]; 64 | 65 | } 66 | 67 | #pragma mark- tableView 68 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 69 | if (section == 0) { 70 | return self.hotCommentsArray.count; 71 | } 72 | 73 | return 0; 74 | } 75 | 76 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 77 | CommentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"comment"]; 78 | 79 | NSDictionary *dic = [_hotCommentsArray objectAtIndex:indexPath.row]; 80 | [cell setContentWithData:dic]; 81 | 82 | return cell; 83 | } 84 | 85 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 86 | NSDictionary *dic = [_hotCommentsArray objectAtIndex:indexPath.row]; 87 | 88 | return [self calculateHeightForData:dic]; 89 | } 90 | 91 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ 92 | return 40; 93 | } 94 | 95 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ 96 | UIView *view = [[UIView alloc] init]; 97 | 98 | UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(-10, 5, 90, 40)]; 99 | imgView.image = [[UIImage imageNamed:@"contentview_commentbacky"] stretchableImageWithLeftCapWidth:20 topCapHeight:22]; 100 | [view addSubview:imgView]; 101 | UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 15, 70, 20)]; 102 | label.font = [UIFont systemFontOfSize:14]; 103 | label.textColor = [UIColor whiteColor]; 104 | label.text = @"热门跟帖"; 105 | [view addSubview:label]; 106 | 107 | return view; 108 | } 109 | 110 | #pragma mark- commonMethod 111 | - (CGFloat)calculateHeightForData:(NSDictionary *)dic{ 112 | NSArray *comArr = [dic allValues]; 113 | int commentLabelY = 66+(int)(comArr.count-1)*3; 114 | 115 | for (int i = 0; i1) { 120 | int thisWidth = SCREEN_WIDTH-16-6*(comArr.count-i); 121 | CGRect rect = [commentText boundingRectWithSize:CGSizeMake(thisWidth, 0) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil]; 122 | 123 | commentLabelY = commentLabelY+rect.size.height+3+20; 124 | }else{ 125 | //评论 126 | CGRect rect = [commentText boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-16, 0) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil]; 127 | 128 | commentLabelY = commentLabelY+rect.size.height; 129 | } 130 | } 131 | return commentLabelY+5; 132 | } 133 | 134 | 135 | 136 | /* 137 | #pragma mark - Navigation 138 | 139 | // In a storyboard-based application, you will often want to do a little preparation before navigation 140 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 141 | // Get the new view controller using [segue destinationViewController]. 142 | // Pass the selected object to the new view controller. 143 | } 144 | */ 145 | 146 | /* 147 | 这是热门评论 148 | http://comment.api.163.com/api/json/post/list/new/hot/3g_bbs/AF661E1900963VRO/0/10/10/2/2 149 | 150 | //http://comment.api.163.com/api/json/post/list/new/hot/news_guonei8_bbs/AFBH38F60001124J/0/10/10/2/2 151 | 152 | 153 | 这个是正常的评论 0-9 154 | http://comment.api.163.com/api/json/post/list/new/normal/3g_bbs/AF661E1900963VRO/desc/0/10/10/2/2 155 | 156 | 分页这是 10-19 157 | http://comment.api.163.com/api/json/post/list/new/normal/3g_bbs/AF661E1900963VRO/desc/10/10/10/2/2 158 | 159 | 这是 20-29 160 | http://comment.api.163.com/api/json/post/list/new/normal/3g_bbs/AF661E1900963VRO/desc/20/10/10/2/2 161 | 162 | 30-39 163 | http://comment.api.163.com/api/json/post/list/new/normal/3g_bbs/AF661E1900963VRO/desc/30/10/10/2/2 164 | */ 165 | 166 | @end 167 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/CommentVC.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/DBPictureVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBPictureVC.h 3 | // AutolayoutDemo 4 | // 5 | // Created by dengbin on 15/1/4. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DBPictureVC : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/DBPictureVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // DBPictureVC.m 3 | // AutolayoutDemo 4 | // 5 | // Created by dengbin on 15/1/4. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "DBPictureVC.h" 10 | 11 | @interface DBPictureVC () 12 | 13 | @end 14 | 15 | @implementation DBPictureVC 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view. 20 | } 21 | 22 | - (void)didReceiveMemoryWarning { 23 | [super didReceiveMemoryWarning]; 24 | // Dispose of any resources that can be recreated. 25 | } 26 | 27 | /* 28 | #pragma mark - Navigation 29 | 30 | // In a storyboard-based application, you will often want to do a little preparation before navigation 31 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 32 | // Get the new view controller using [segue destinationViewController]. 33 | // Pass the selected object to the new view controller. 34 | } 35 | */ 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsCenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // NewsCenter.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NewsCenter : NSObject 12 | 13 | 14 | //保存本地新闻栏目列表 15 | +(void)saveLocalNewsColumn:(NSArray*)array; 16 | //获取本地新闻栏目列表 17 | +(void)localNewsColumnWithComplection:(void(^)(NSArray *array))completion; 18 | 19 | 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsCenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // NewsCenter.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NewsCenter.h" 10 | #import "WTNetWork.h" 11 | #import "UIKit+WTRequestCenter.h" 12 | @implementation NewsCenter 13 | 14 | 15 | static NSString *localColumnName = @"NewsCenter local column name"; 16 | 17 | +(void)saveLocalNewsColumn:(NSArray*)array 18 | { 19 | assert(!array); 20 | [WTDataSaver saveData:[NSJSONSerialization dataWithJSONObject:array options:0 error:nil] withName:localColumnName]; 21 | } 22 | 23 | +(void)localNewsColumnWithComplection:(void(^)(NSArray *array))completion 24 | { 25 | // NSArray *result = nil; 26 | [WTDataSaver dataWithName:localColumnName 27 | completion:^(NSData *data) { 28 | 29 | NSArray *array = [WTRequestCenter JSONObjectWithData:data]; 30 | 31 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 32 | if (completion) { 33 | completion(array); 34 | } 35 | }]; 36 | 37 | }]; 38 | 39 | 40 | } 41 | 42 | 43 | //获取新闻的分类 44 | +(void)getNewsCategoty 45 | { 46 | 47 | 48 | //http://c.m.163.com/nc/topicset/ios/v4/subscribe/news/all.html 49 | [WTRequestCenter getWithURL:@"http://c.m.163.com/nc/topicset/ios/v4/subscribe/news/all.html" 50 | parameters:nil 51 | option:WTRequestCenterCachePolicyNormal 52 | finished:^(NSURLResponse *response, NSData *data) { 53 | NSDictionary *dict = [WTRequestCenter JSONObjectWithData:data]; 54 | NSLog(@"当前新闻分类 %@",dict); 55 | } failed:^(NSURLResponse *response, NSError *error) { 56 | 57 | }]; 58 | } 59 | @end 60 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsDetailViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // NewsDetailViewController.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NS_ENUM(NSUInteger, NewsType) { 12 | NewsTypeNormal, //正常新闻 13 | NewsTypeAtlas //图集新闻 14 | }; 15 | 16 | @interface NewsDetailViewController : UIViewController 17 | 18 | @property (nonatomic,strong) NSDictionary *articleInfo; //传入的文章基本数据 19 | 20 | 21 | @property (nonatomic,strong) NSDictionary *newsData; //从服务器访问的的文章详细数据 22 | 23 | 24 | /*! 25 | 使用数据请求到的新闻详情数据 26 | */ 27 | -(void)useData; 28 | @end 29 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsDetailViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // NewsDetailViewController.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NewsDetailViewController.h" 10 | #import "WTNetWork.h" 11 | #import "CommentVC.h" 12 | @interface NewsDetailViewController () 13 | { 14 | 15 | } 16 | 17 | 18 | 19 | 20 | 21 | 22 | @end 23 | 24 | @implementation NewsDetailViewController 25 | 26 | - (void)viewDidLoad { 27 | [super viewDidLoad]; 28 | // Do any additional setup after loading the view. 29 | 30 | } 31 | 32 | 33 | 34 | -(void)viewWillAppear:(BOOL)animated 35 | { 36 | [super viewWillAppear:animated]; 37 | 38 | [self loadData]; 39 | 40 | 41 | } 42 | 43 | -(void)loadData 44 | { 45 | if (!_newsData) { 46 | 47 | // hasHead 48 | // hasIcon 49 | 50 | NewsType type; 51 | 52 | // 新闻ID 53 | NSString *docid = [_articleInfo valueForKey:@"docid"]; 54 | NSString *url; 55 | if ([_articleInfo valueForKey:@"photosetID"]) { 56 | type = NewsTypeAtlas; 57 | // 54GI0096|55534 http://c.m.163.com/photo/api/set/0096/54GI0096|55534.json 58 | // http://c.m.163.com/photo/api/set/0096/55411.json 59 | NSString *photosetID = [_articleInfo valueForKey:@"photosetID"]; 60 | photosetID = [[photosetID componentsSeparatedByString:@"|"] lastObject]; 61 | url = [NSString stringWithFormat:@"http://c.m.163.com/photo/api/set/0096/%@.json",photosetID]; 62 | }else 63 | { 64 | type = NewsTypeNormal; 65 | url = [NSString stringWithFormat:@"http://c.m.163.com/nc/article/%@/full.html",docid]; 66 | } 67 | 68 | 69 | 70 | 71 | [WTRequestCenter getWithURL:url 72 | parameters:nil 73 | option:WTRequestCenterCachePolicyCacheAndWeb 74 | finished:^(NSURLResponse *response, NSData *data) 75 | { 76 | 77 | NSString *docid = [_articleInfo valueForKey:@"docid"]; 78 | NSDictionary *dict = [WTRequestCenter JSONObjectWithData:data]; 79 | if ([dict valueForKey:docid]) { 80 | dict = [dict valueForKey:docid]; 81 | } 82 | 83 | self.newsData = dict; 84 | [self useData]; 85 | 86 | } 87 | failed:^(NSURLResponse *response, NSError *error) 88 | { 89 | 90 | }]; 91 | } 92 | 93 | } 94 | 95 | 96 | 97 | -(void)useData 98 | { 99 | 100 | 101 | 102 | // 设置右上角的评论按钮 103 | NSDictionary *dict = self.newsData; 104 | NSNumber *replyCount = [dict valueForKey:@"replyCount"]; 105 | NSString *replyCountString = [NSString stringWithFormat:@"%@评论",replyCount]; 106 | 107 | 108 | UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:replyCountString 109 | style:UIBarButtonItemStylePlain 110 | target:self 111 | action:@selector(commentButtonPressed:)]; 112 | self.navigationItem.rightBarButtonItem = item; 113 | 114 | 115 | } 116 | 117 | 118 | //评论点击 119 | -(void)commentButtonPressed:(id)sender 120 | { 121 | CommentVC *vc = [[CommentVC alloc] init]; 122 | vc.articleInfo = _articleInfo; 123 | [self.navigationController pushViewController:vc animated:YES]; 124 | 125 | } 126 | 127 | - (void)didReceiveMemoryWarning { 128 | [super didReceiveMemoryWarning]; 129 | // Dispose of any resources that can be recreated. 130 | } 131 | 132 | /* 133 | #pragma mark - Navigation 134 | 135 | // In a storyboard-based application, you will often want to do a little preparation before navigation 136 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 137 | // Get the new view controller using [segue destinationViewController]. 138 | // Pass the selected object to the new view controller. 139 | } 140 | */ 141 | 142 | @end 143 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsHeadTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // NewsHeadTableViewCell.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/6. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | //新闻的头 11 | @interface NewsHeadTableViewCell : UITableViewCell 12 | @property (nonatomic,strong) NSDictionary *newsInfo; 13 | 14 | 15 | 16 | 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsHeadTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // NewsHeadTableViewCell.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/6. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NewsHeadTableViewCell.h" 10 | //#import "WTNetWork.h" 11 | #import "UIKit+WTRequestCenter.h" 12 | @interface NewsHeadTableViewCell() 13 | { 14 | 15 | // 图片数组 16 | NSMutableArray *_imageArray; 17 | 18 | // 标题 19 | UILabel *_titleLabel; 20 | } 21 | 22 | 23 | @end 24 | @implementation NewsHeadTableViewCell 25 | 26 | - (void)awakeFromNib { 27 | // Initialization code 28 | _imageArray = [[NSMutableArray alloc] init]; 29 | } 30 | 31 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 32 | [super setSelected:selected animated:animated]; 33 | 34 | // Configure the view for the selected state 35 | } 36 | 37 | 38 | -(void)layoutSubviews 39 | { 40 | [super layoutSubviews]; 41 | [_imageArray enumerateObjectsUsingBlock:^(UIImageView *imageView, NSUInteger idx, BOOL *stop) { 42 | [imageView removeFromSuperview]; 43 | }]; 44 | [_imageArray removeAllObjects]; 45 | 46 | 47 | 48 | NSArray *imgextra = [_newsInfo valueForKey:@"imgextra"]; 49 | NSUInteger count = [imgextra count]; 50 | 51 | CGFloat width = CGRectGetWidth(self.bounds); 52 | CGFloat height = CGRectGetHeight(self.bounds); 53 | 54 | 55 | switch (count) { 56 | case 0: 57 | { 58 | NSString *imgsrc = [_newsInfo valueForKey:@"imgsrc"]; 59 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; 60 | [imageView setImageWithURL:imgsrc]; 61 | [self.contentView addSubview:imageView]; 62 | [_imageArray addObject:imageView]; 63 | 64 | } 65 | break; 66 | case 1: 67 | { 68 | [imgextra enumerateObjectsUsingBlock:^(NSDictionary *info, NSUInteger idx, BOOL *stop) { 69 | NSString *imgsrc = [info valueForKey:@"imgsrc"]; 70 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; 71 | [imageView setImageWithURL:imgsrc]; 72 | [self.contentView addSubview:imageView]; 73 | [_imageArray addObject:imageView]; 74 | }]; 75 | } 76 | break; 77 | case 2: 78 | { 79 | [imgextra enumerateObjectsUsingBlock:^(NSDictionary *info, NSUInteger idx, BOOL *stop) { 80 | NSString *imgsrc = [info valueForKey:@"imgsrc"]; 81 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(width/2*idx, 0, width/2, height)]; 82 | [imageView setImageWithURL:imgsrc]; 83 | [self.contentView addSubview:imageView]; 84 | [_imageArray addObject:imageView]; 85 | }]; 86 | } 87 | break; 88 | default: 89 | break; 90 | } 91 | 92 | 93 | 94 | 95 | // NSLog(@"%@",imgsrc); 96 | } 97 | @end 98 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsHeadTableViewCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsImageCollectionViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // NewsImageCollectionViewCell.h 3 | // AutolayoutDemo 4 | // 5 | // Created by SongWentong on 15/1/13. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NewsImageCollectionViewCell : UICollectionViewCell 12 | @property (nonatomic,strong) NSDictionary *imageInfo; 13 | @property (strong, nonatomic) UIScrollView *imageScrollView; 14 | @property (strong, nonatomic) UIImageView *newsImageView; 15 | 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsImageCollectionViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // NewsImageCollectionViewCell.m 3 | // AutolayoutDemo 4 | // 5 | // Created by SongWentong on 15/1/13. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NewsImageCollectionViewCell.h" 10 | #import "UIKit+WTRequestCenter.h" 11 | @interface NewsImageCollectionViewCell() 12 | @end 13 | @implementation NewsImageCollectionViewCell 14 | 15 | - (void)awakeFromNib { 16 | // Initialization code 17 | [super awakeFromNib]; 18 | 19 | } 20 | 21 | -(void)prepareForReuse 22 | { 23 | [super prepareForReuse]; 24 | _imageScrollView.zoomScale = 1.0; 25 | } 26 | 27 | -(void)layoutSubviews 28 | { 29 | [super layoutSubviews]; 30 | if (!_newsImageView) { 31 | self.imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero]; 32 | _imageScrollView.delegate = self; 33 | [self.contentView addSubview:_imageScrollView]; 34 | 35 | _imageScrollView.maximumZoomScale = 2.0; 36 | _imageScrollView.minimumZoomScale = 1.0; 37 | 38 | 39 | self.newsImageView = [[UIImageView alloc] initWithFrame:CGRectZero]; 40 | [_imageScrollView addSubview:_newsImageView]; 41 | } 42 | _imageScrollView.frame = self.contentView.bounds; 43 | _newsImageView.frame = _imageScrollView.bounds; 44 | // self.contentView.backgroundColor = [UIColor greenColor]; 45 | // NSLog(@"%@ layoutSubViews",self); 46 | 47 | 48 | 49 | 50 | } 51 | 52 | #pragma mark - UIScrollViewDelegate 53 | - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 54 | { 55 | if (_newsImageView) { 56 | return _newsImageView; 57 | }else 58 | { 59 | return nil; 60 | } 61 | // return _newsImageView; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsImageCollectionViewCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsTableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // NewsTableView.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | @class NewsTableView; 11 | @protocol NewsTableViewDelegate 12 | 13 | -(void)newsTableView:(NewsTableView*)tableView selectArticleWithInfo:(NSDictionary*)info; 14 | 15 | @end 16 | @interface NewsTableView : UICollectionViewCell 17 | @property (nonatomic,weak) id delegate; 18 | 19 | @property (nonatomic,strong) NSDictionary *newsDict; 20 | -(void)reloadData; 21 | @end 22 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // NewsTableViewCell.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class NewsTableViewCell; 12 | @protocol NewsTableViewCellDataSource 13 | //图片 14 | -(NSString*)urlForNewsTableViewCell:(NewsTableViewCell*)cell; 15 | //标题 16 | -(NSString*)titleForNewsTableViewCell:(NewsTableViewCell*)cell; 17 | //附标题 18 | -(NSString*)digestForNewsTableViewCell:(NewsTableViewCell*)cell; 19 | //跟帖数量 20 | -(NSString*)replyCountForNewsTableViewCell:(NewsTableViewCell*)cell; 21 | @end 22 | 23 | @interface NewsTableViewCell : UITableViewCell 24 | 25 | @property (nonatomic,weak) id dataSource; 26 | 27 | @end 28 | 29 | 30 | //file:///Users/song/https:/github.com/rs/EasyNews/AutolayoutDemo/View%20and%20ViewControllers/NewsTableViewCell.xib: warning: Attribute Unavailable: Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0 31 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // NewsTableViewCell.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NewsTableViewCell.h" 10 | #import "UIKit+WTRequestCenter.h" 11 | #import "WTNetWork.h" 12 | @interface NewsTableViewCell () 13 | 14 | @property (weak, nonatomic) IBOutlet UIImageView *newsImage; 15 | @property (weak, nonatomic) IBOutlet UILabel *newsTitle; 16 | @property (weak, nonatomic) IBOutlet UILabel *newsContent; 17 | @property (weak, nonatomic) IBOutlet UILabel *numberOfReplyLabel; 18 | 19 | @end 20 | @implementation NewsTableViewCell 21 | 22 | - (void)awakeFromNib { 23 | // Initialization code 24 | [super awakeFromNib]; 25 | } 26 | 27 | 28 | -(void)prepareForReuse 29 | { 30 | [super prepareForReuse]; 31 | _newsImage.image = nil; 32 | WTURLRequestOperation *operation = _newsImage.wtImageRequestOperation; 33 | [operation cancel]; 34 | } 35 | 36 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 37 | [super setSelected:selected animated:animated]; 38 | 39 | // Configure the view for the selected state 40 | } 41 | 42 | 43 | -(void)layoutSubviews 44 | { 45 | [super layoutSubviews]; 46 | 47 | 48 | NSString *url = [self.dataSource urlForNewsTableViewCell:self]; 49 | [_newsImage setImageWithURL:url]; 50 | 51 | NSString *title = [self.dataSource titleForNewsTableViewCell:self]; 52 | _newsTitle.text = title; 53 | 54 | NSString *digest = [self.dataSource digestForNewsTableViewCell:self]; 55 | _newsContent.text = digest; 56 | 57 | NSString* replyCount = [self.dataSource replyCountForNewsTableViewCell:self]; 58 | if ([replyCount isEqual:[NSNull null]]) { 59 | _numberOfReplyLabel.hidden = YES; 60 | }else 61 | { 62 | _numberOfReplyLabel.hidden = NO; 63 | _numberOfReplyLabel.text = [NSString stringWithFormat:@"%@跟帖",replyCount]; 64 | } 65 | /* 66 | NSString *imgsrc = [_newsData valueForKey:@"imgsrc"]; 67 | [_newsImage setImageWithURL:imgsrc]; 68 | 69 | NSString *title = [_newsData valueForKey:@"title"]; 70 | _newsTitle.text = title; 71 | 72 | NSString *digest = [_newsData valueForKey:@"digest"]; 73 | _newsContent.text = digest; 74 | 75 | NSNumber *replyCount = [_newsData valueForKey:@"replyCount"]; 76 | if ([replyCount isEqual:[NSNull null]]) { 77 | _numberOfReplyLabel.hidden = YES; 78 | }else 79 | { 80 | _numberOfReplyLabel.hidden = NO; 81 | } 82 | _numberOfReplyLabel.text = [NSString stringWithFormat:@"%@跟帖",replyCount]; 83 | */ 84 | 85 | } 86 | 87 | @end 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsTableViewCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 45 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsTitleCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // NewsTitleCell.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NewsTitleCell : UICollectionViewCell 12 | @property (nonatomic,strong) NSDictionary *infoDict; 13 | 14 | @property (weak, nonatomic) IBOutlet UILabel *newsTitle; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NewsTitleCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // NewsTitleCell.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NewsTitleCell.h" 10 | 11 | @implementation NewsTitleCell 12 | 13 | -(void)setSelected:(BOOL)selected 14 | { 15 | [super setSelected:selected]; 16 | 17 | UIColor *textColor; 18 | UIFont *font; 19 | if (selected) { 20 | textColor = [UIColor redColor]; 21 | font = [UIFont systemFontOfSize:18]; 22 | }else 23 | { 24 | textColor = [UIColor blackColor]; 25 | font = [UIFont systemFontOfSize:14]; 26 | } 27 | 28 | 29 | [UIView animateWithDuration:0.45 30 | delay:0 31 | options:UIViewAnimationOptionBeginFromCurrentState 32 | animations:^{ 33 | _newsTitle.textColor = textColor; 34 | _newsTitle.font = font; 35 | } completion:nil]; 36 | 37 | } 38 | 39 | -(void)layoutSubviews 40 | { 41 | [super layoutSubviews]; 42 | 43 | self.backgroundColor = [UIColor clearColor]; 44 | 45 | NSArray *tList = [_infoDict valueForKey:@"tList"]; 46 | NSDictionary *dict = [tList firstObject]; 47 | NSString *tname = [dict valueForKey:@"tname"]; 48 | _newsTitle.text = tname; 49 | 50 | // NSLog(@"%@",dict); 51 | } 52 | @end 53 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NormalNewDetailVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // NormalNewDetailVC.h 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/10. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NewsDetailViewController.h" 10 | //常规新闻详情 11 | @interface NormalNewDetailVC : NewsDetailViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NormalNewDetailVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // NormalNewDetailVC.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/10. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import "NormalNewDetailVC.h" 10 | #import "WTNetWork.h" 11 | #import "UIKit+WTRequestCenter.h" 12 | @interface NormalNewDetailVC () 13 | { 14 | CGFloat _webViewHeight; 15 | } 16 | @property (strong, nonatomic) UIWebView *myWebView; 17 | 18 | 19 | @property (weak, nonatomic) IBOutlet UITableView *myTableView; 20 | 21 | @end 22 | 23 | @implementation NormalNewDetailVC 24 | 25 | - (void)viewDidLoad { 26 | [super viewDidLoad]; 27 | // Do any additional setup after loading the view from its nib. 28 | _myWebView.hidden = YES; 29 | _webViewHeight = 0; 30 | self.myWebView = [[UIWebView alloc] init]; 31 | _myWebView.delegate = self; 32 | _myWebView.backgroundColor = [UIColor redColor]; 33 | 34 | } 35 | 36 | -(void)viewDidAppear:(BOOL)animated 37 | { 38 | [super viewDidAppear:animated]; 39 | 40 | } 41 | 42 | - (void)didReceiveMemoryWarning { 43 | [super didReceiveMemoryWarning]; 44 | // Dispose of any resources that can be recreated. 45 | } 46 | 47 | -(void)useData 48 | { 49 | [super useData]; 50 | 51 | 52 | NSString *docid = [self.articleInfo valueForKey:@"docid"]; 53 | NSDictionary *dict = self.newsData; 54 | NSString *body = [dict valueForKey:@"body"]; 55 | dict = [dict valueForKey:docid]; 56 | 57 | _myWebView.hidden = NO; 58 | 59 | CGRect frame = _myTableView.frame; 60 | frame.size.width = CGRectGetWidth(self.view.bounds); 61 | _myTableView.frame = frame; 62 | 63 | if ([_myWebView isLoading]) { 64 | [_myWebView stopLoading]; 65 | } 66 | [_myWebView loadHTMLString:body baseURL:nil]; 67 | 68 | } 69 | 70 | 71 | #pragma mark - UITableViewDataSource 72 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 73 | { 74 | return 2; 75 | } 76 | 77 | // Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier: 78 | // Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls) 79 | 80 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 81 | { 82 | UITableViewCell *cell = nil; 83 | cell = [UITableViewCell new]; 84 | switch (indexPath.row) { 85 | case 0: 86 | { 87 | NSString *title = [self.newsData valueForKeyPath:@"title"]; 88 | cell.textLabel.text = title; 89 | 90 | } 91 | break; 92 | case 1: 93 | { 94 | [cell.contentView addSubview:_myWebView]; 95 | } 96 | break; 97 | 98 | default: 99 | break; 100 | } 101 | 102 | 103 | cell.selectionStyle = UITableViewCellSelectionStyleNone; 104 | return cell; 105 | } 106 | 107 | #pragma mark - UITableViewDelegate 108 | - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 109 | { 110 | // cell.backgroundColor = [UIColor redColor]; 111 | } 112 | - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath 113 | { 114 | _myWebView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), _webViewHeight); 115 | 116 | } 117 | 118 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 119 | { 120 | CGFloat height = 0; 121 | 122 | switch (indexPath.row) { 123 | case 0: 124 | { 125 | height = 44; 126 | } 127 | break; 128 | case 1: 129 | { 130 | height = _webViewHeight; 131 | } 132 | break; 133 | 134 | default: 135 | break; 136 | } 137 | 138 | return height; 139 | } 140 | 141 | 142 | #pragma mark - UIWebViewDelegate 143 | - (void)webViewDidFinishLoad:(UIWebView *)webView 144 | { 145 | 146 | webView.scrollView.scrollEnabled = NO; 147 | CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue]; 148 | _webViewHeight = height; 149 | [_myTableView reloadData]; 150 | 151 | } 152 | 153 | 154 | - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 155 | { 156 | // NSLog(@"%@",error); 157 | [UIAlertView showAlertWithMessage:@"加载失败"]; 158 | } 159 | /* 160 | #pragma mark - Navigation 161 | 162 | // In a storyboard-based application, you will often want to do a little preparation before navigation 163 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 164 | // Get the new view controller using [segue destinationViewController]. 165 | // Pass the selected object to the new view controller. 166 | } 167 | */ 168 | 169 | @end 170 | -------------------------------------------------------------------------------- /AutolayoutDemo/View and ViewControllers/NormalNewDetailVC.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /AutolayoutDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // AutolayoutDemo 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /AutolayoutDemoTests/AutolayoutDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // AutolayoutDemoTests.m 3 | // AutolayoutDemoTests 4 | // 5 | // Created by song on 15/1/2. 6 | // Copyright (c) 2015年 song. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface AutolayoutDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation AutolayoutDemoTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /AutolayoutDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | myCom.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 中国iOS开发者 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | EasyNews 2 | ======== 3 | 4 | 网易新闻无广告山寨版本😄 5 | 6 | 7 | 8 | ##编程规范 9 | - 使用storyboard(简称sb)来调整自动布局. 10 | - 头文件能不import就不要import文件,节省编译时间. 11 | - 命名要规范,全局变量前面加上下划线。 12 | - push之前尽量去掉或者注释掉输出,多注意,方便debug. 13 | - 协议用"#pragma mark - protocol"来标记. 14 | - 头文件要有一定量的注释. 15 | - 不使用prefix header 文件,节省编译时间. 16 | - 图片使用Images.xcassets. 17 | - View千万不要处理业务逻辑.否则别怪我驳回代码. 18 | - 能用OperationQueue的地方不要用GCD. 19 | - 常量不要用宏定义指定,用静态变量声明. 20 | - 用分析去查看内存用错的地方. 21 | - 用Profile测试程序的性能. 22 | 23 | 24 | ##MVC 25 | ###View的做法 26 | View的功能就是展示UI,不储存任何数据,不参与任何业务逻辑 27 | View的数据来源是Datasource,交互事件是Delegate 28 | 29 | ###Controller 30 | 程序的中心,对Model和V有绝对的控制权,业务的核心。 31 | 32 | ###Model 33 | Model要求不高,用原生数据类型或者jsonModel生成的都可以。 34 | 通常情况下Controller去修改model,修改完后该刷新UI刷新UI。 35 | 36 | 37 | ###总结 38 | - Controller对Model和View的绝对控制权。 39 | - Model通过Notification来通知Controller数据发生了变化。 40 | - View通过Datasource或者Delegate来告知Controller自己发生了变化/是否需要发生变化。 41 | - Model和View不直接通信,没有任何关系。 42 | - Controller之间可以互相帮忙,大量的Controller结合起来就形成了一个完整的程序 --------------------------------------------------------------------------------