├── .DS_Store ├── .gitignore ├── LICENSE ├── README.md └── Runloop-性能优化,加载大图 ├── .DS_Store ├── Runloop-性能优化,加载大图.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── Runloop-性能优化,加载大图 ├── .DS_Store ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── RunloopClass ├── PQRunloop.h ├── PQRunloop.m ├── PQSingle.h ├── Utils.h └── Utils.m ├── ViewController.h ├── ViewController.m ├── main.m └── spaceship.jpg /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codepgq/RunloopDemo/19722f0d94f0c151fd09d9f90d24bc40f4e2e22f/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RunloopDemo -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codepgq/RunloopDemo/19722f0d94f0c151fd09d9f90d24bc40f4e2e22f/Runloop-性能优化,加载大图/.DS_Store -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 601067451E65AFFA00481C99 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 601067441E65AFFA00481C99 /* main.m */; }; 11 | 601067481E65AFFA00481C99 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 601067471E65AFFA00481C99 /* AppDelegate.m */; }; 12 | 6010674E1E65AFFA00481C99 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6010674C1E65AFFA00481C99 /* Main.storyboard */; }; 13 | 601067501E65AFFA00481C99 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6010674F1E65AFFA00481C99 /* Assets.xcassets */; }; 14 | 601067531E65AFFA00481C99 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 601067511E65AFFA00481C99 /* LaunchScreen.storyboard */; }; 15 | 601067611E66B11700481C99 /* PQRunloop.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010675F1E66B11700481C99 /* PQRunloop.m */; }; 16 | 601067631E66B98B00481C99 /* spaceship.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 601067621E66B98B00481C99 /* spaceship.jpg */; }; 17 | 601492CC1E66D33500865CB1 /* Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 601492CB1E66D33500865CB1 /* Utils.m */; }; 18 | 601492F21E6716B800865CB1 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010674A1E65AFFA00481C99 /* ViewController.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 601067401E65AFFA00481C99 /* Runloop-性能优化,加载大图.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Runloop-性能优化,加载大图.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 601067441E65AFFA00481C99 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 24 | 601067461E65AFFA00481C99 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | 601067471E65AFFA00481C99 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | 601067491E65AFFA00481C99 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 27 | 6010674A1E65AFFA00481C99 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 28 | 6010674D1E65AFFA00481C99 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | 6010674F1E65AFFA00481C99 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | 601067521E65AFFA00481C99 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | 601067541E65AFFA00481C99 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 6010675E1E66B11700481C99 /* PQRunloop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PQRunloop.h; sourceTree = ""; }; 33 | 6010675F1E66B11700481C99 /* PQRunloop.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PQRunloop.m; sourceTree = ""; }; 34 | 601067601E66B11700481C99 /* PQSingle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PQSingle.h; sourceTree = ""; }; 35 | 601067621E66B98B00481C99 /* spaceship.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = spaceship.jpg; sourceTree = ""; }; 36 | 601492CA1E66D33500865CB1 /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Utils.h; sourceTree = ""; }; 37 | 601492CB1E66D33500865CB1 /* Utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Utils.m; sourceTree = ""; }; 38 | /* End PBXFileReference section */ 39 | 40 | /* Begin PBXFrameworksBuildPhase section */ 41 | 6010673D1E65AFFA00481C99 /* Frameworks */ = { 42 | isa = PBXFrameworksBuildPhase; 43 | buildActionMask = 2147483647; 44 | files = ( 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | /* End PBXFrameworksBuildPhase section */ 49 | 50 | /* Begin PBXGroup section */ 51 | 601067371E65AFFA00481C99 = { 52 | isa = PBXGroup; 53 | children = ( 54 | 601067421E65AFFA00481C99 /* Runloop-性能优化,加载大图 */, 55 | 601067411E65AFFA00481C99 /* Products */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | 601067411E65AFFA00481C99 /* Products */ = { 60 | isa = PBXGroup; 61 | children = ( 62 | 601067401E65AFFA00481C99 /* Runloop-性能优化,加载大图.app */, 63 | ); 64 | name = Products; 65 | sourceTree = ""; 66 | }; 67 | 601067421E65AFFA00481C99 /* Runloop-性能优化,加载大图 */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | 601067621E66B98B00481C99 /* spaceship.jpg */, 71 | 6010675D1E66B11700481C99 /* RunloopClass */, 72 | 601067461E65AFFA00481C99 /* AppDelegate.h */, 73 | 601067471E65AFFA00481C99 /* AppDelegate.m */, 74 | 601067491E65AFFA00481C99 /* ViewController.h */, 75 | 6010674A1E65AFFA00481C99 /* ViewController.m */, 76 | 6010674C1E65AFFA00481C99 /* Main.storyboard */, 77 | 6010674F1E65AFFA00481C99 /* Assets.xcassets */, 78 | 601067511E65AFFA00481C99 /* LaunchScreen.storyboard */, 79 | 601067541E65AFFA00481C99 /* Info.plist */, 80 | 601067431E65AFFA00481C99 /* Supporting Files */, 81 | ); 82 | path = "Runloop-性能优化,加载大图"; 83 | sourceTree = ""; 84 | }; 85 | 601067431E65AFFA00481C99 /* Supporting Files */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | 601067441E65AFFA00481C99 /* main.m */, 89 | ); 90 | name = "Supporting Files"; 91 | sourceTree = ""; 92 | }; 93 | 6010675D1E66B11700481C99 /* RunloopClass */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 6010675E1E66B11700481C99 /* PQRunloop.h */, 97 | 6010675F1E66B11700481C99 /* PQRunloop.m */, 98 | 601067601E66B11700481C99 /* PQSingle.h */, 99 | 601492CA1E66D33500865CB1 /* Utils.h */, 100 | 601492CB1E66D33500865CB1 /* Utils.m */, 101 | ); 102 | path = RunloopClass; 103 | sourceTree = ""; 104 | }; 105 | /* End PBXGroup section */ 106 | 107 | /* Begin PBXNativeTarget section */ 108 | 6010673F1E65AFFA00481C99 /* Runloop-性能优化,加载大图 */ = { 109 | isa = PBXNativeTarget; 110 | buildConfigurationList = 601067571E65AFFA00481C99 /* Build configuration list for PBXNativeTarget "Runloop-性能优化,加载大图" */; 111 | buildPhases = ( 112 | 6010673C1E65AFFA00481C99 /* Sources */, 113 | 6010673D1E65AFFA00481C99 /* Frameworks */, 114 | 6010673E1E65AFFA00481C99 /* Resources */, 115 | ); 116 | buildRules = ( 117 | ); 118 | dependencies = ( 119 | ); 120 | name = "Runloop-性能优化,加载大图"; 121 | productName = "Runloop-性能优化,加载大图"; 122 | productReference = 601067401E65AFFA00481C99 /* Runloop-性能优化,加载大图.app */; 123 | productType = "com.apple.product-type.application"; 124 | }; 125 | /* End PBXNativeTarget section */ 126 | 127 | /* Begin PBXProject section */ 128 | 601067381E65AFFA00481C99 /* Project object */ = { 129 | isa = PBXProject; 130 | attributes = { 131 | LastUpgradeCheck = 0820; 132 | ORGANIZATIONNAME = pgq; 133 | TargetAttributes = { 134 | 6010673F1E65AFFA00481C99 = { 135 | CreatedOnToolsVersion = 8.2; 136 | ProvisioningStyle = Automatic; 137 | }; 138 | }; 139 | }; 140 | buildConfigurationList = 6010673B1E65AFFA00481C99 /* Build configuration list for PBXProject "Runloop-性能优化,加载大图" */; 141 | compatibilityVersion = "Xcode 3.2"; 142 | developmentRegion = English; 143 | hasScannedForEncodings = 0; 144 | knownRegions = ( 145 | en, 146 | Base, 147 | ); 148 | mainGroup = 601067371E65AFFA00481C99; 149 | productRefGroup = 601067411E65AFFA00481C99 /* Products */; 150 | projectDirPath = ""; 151 | projectRoot = ""; 152 | targets = ( 153 | 6010673F1E65AFFA00481C99 /* Runloop-性能优化,加载大图 */, 154 | ); 155 | }; 156 | /* End PBXProject section */ 157 | 158 | /* Begin PBXResourcesBuildPhase section */ 159 | 6010673E1E65AFFA00481C99 /* Resources */ = { 160 | isa = PBXResourcesBuildPhase; 161 | buildActionMask = 2147483647; 162 | files = ( 163 | 601067631E66B98B00481C99 /* spaceship.jpg in Resources */, 164 | 601067531E65AFFA00481C99 /* LaunchScreen.storyboard in Resources */, 165 | 601067501E65AFFA00481C99 /* Assets.xcassets in Resources */, 166 | 6010674E1E65AFFA00481C99 /* Main.storyboard in Resources */, 167 | ); 168 | runOnlyForDeploymentPostprocessing = 0; 169 | }; 170 | /* End PBXResourcesBuildPhase section */ 171 | 172 | /* Begin PBXSourcesBuildPhase section */ 173 | 6010673C1E65AFFA00481C99 /* Sources */ = { 174 | isa = PBXSourcesBuildPhase; 175 | buildActionMask = 2147483647; 176 | files = ( 177 | 601067481E65AFFA00481C99 /* AppDelegate.m in Sources */, 178 | 601067611E66B11700481C99 /* PQRunloop.m in Sources */, 179 | 601492CC1E66D33500865CB1 /* Utils.m in Sources */, 180 | 601067451E65AFFA00481C99 /* main.m in Sources */, 181 | 601492F21E6716B800865CB1 /* ViewController.m in Sources */, 182 | ); 183 | runOnlyForDeploymentPostprocessing = 0; 184 | }; 185 | /* End PBXSourcesBuildPhase section */ 186 | 187 | /* Begin PBXVariantGroup section */ 188 | 6010674C1E65AFFA00481C99 /* Main.storyboard */ = { 189 | isa = PBXVariantGroup; 190 | children = ( 191 | 6010674D1E65AFFA00481C99 /* Base */, 192 | ); 193 | name = Main.storyboard; 194 | sourceTree = ""; 195 | }; 196 | 601067511E65AFFA00481C99 /* LaunchScreen.storyboard */ = { 197 | isa = PBXVariantGroup; 198 | children = ( 199 | 601067521E65AFFA00481C99 /* Base */, 200 | ); 201 | name = LaunchScreen.storyboard; 202 | sourceTree = ""; 203 | }; 204 | /* End PBXVariantGroup section */ 205 | 206 | /* Begin XCBuildConfiguration section */ 207 | 601067551E65AFFA00481C99 /* Debug */ = { 208 | isa = XCBuildConfiguration; 209 | buildSettings = { 210 | ALWAYS_SEARCH_USER_PATHS = NO; 211 | CLANG_ANALYZER_NONNULL = YES; 212 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 213 | CLANG_CXX_LIBRARY = "libc++"; 214 | CLANG_ENABLE_MODULES = YES; 215 | CLANG_ENABLE_OBJC_ARC = YES; 216 | CLANG_WARN_BOOL_CONVERSION = YES; 217 | CLANG_WARN_CONSTANT_CONVERSION = YES; 218 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 219 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 220 | CLANG_WARN_EMPTY_BODY = YES; 221 | CLANG_WARN_ENUM_CONVERSION = YES; 222 | CLANG_WARN_INFINITE_RECURSION = YES; 223 | CLANG_WARN_INT_CONVERSION = YES; 224 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 225 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 226 | CLANG_WARN_UNREACHABLE_CODE = YES; 227 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 228 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 229 | COPY_PHASE_STRIP = NO; 230 | DEBUG_INFORMATION_FORMAT = dwarf; 231 | ENABLE_STRICT_OBJC_MSGSEND = YES; 232 | ENABLE_TESTABILITY = YES; 233 | GCC_C_LANGUAGE_STANDARD = gnu99; 234 | GCC_DYNAMIC_NO_PIC = NO; 235 | GCC_NO_COMMON_BLOCKS = YES; 236 | GCC_OPTIMIZATION_LEVEL = 0; 237 | GCC_PREPROCESSOR_DEFINITIONS = ( 238 | "DEBUG=1", 239 | "$(inherited)", 240 | ); 241 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 242 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 243 | GCC_WARN_UNDECLARED_SELECTOR = YES; 244 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 245 | GCC_WARN_UNUSED_FUNCTION = YES; 246 | GCC_WARN_UNUSED_VARIABLE = YES; 247 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 248 | MTL_ENABLE_DEBUG_INFO = YES; 249 | ONLY_ACTIVE_ARCH = YES; 250 | SDKROOT = iphoneos; 251 | TARGETED_DEVICE_FAMILY = "1,2"; 252 | }; 253 | name = Debug; 254 | }; 255 | 601067561E65AFFA00481C99 /* Release */ = { 256 | isa = XCBuildConfiguration; 257 | buildSettings = { 258 | ALWAYS_SEARCH_USER_PATHS = NO; 259 | CLANG_ANALYZER_NONNULL = YES; 260 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 261 | CLANG_CXX_LIBRARY = "libc++"; 262 | CLANG_ENABLE_MODULES = YES; 263 | CLANG_ENABLE_OBJC_ARC = YES; 264 | CLANG_WARN_BOOL_CONVERSION = YES; 265 | CLANG_WARN_CONSTANT_CONVERSION = YES; 266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 267 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 268 | CLANG_WARN_EMPTY_BODY = YES; 269 | CLANG_WARN_ENUM_CONVERSION = YES; 270 | CLANG_WARN_INFINITE_RECURSION = YES; 271 | CLANG_WARN_INT_CONVERSION = YES; 272 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 273 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 274 | CLANG_WARN_UNREACHABLE_CODE = YES; 275 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 276 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 277 | COPY_PHASE_STRIP = NO; 278 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 279 | ENABLE_NS_ASSERTIONS = NO; 280 | ENABLE_STRICT_OBJC_MSGSEND = YES; 281 | GCC_C_LANGUAGE_STANDARD = gnu99; 282 | GCC_NO_COMMON_BLOCKS = YES; 283 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 284 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 285 | GCC_WARN_UNDECLARED_SELECTOR = YES; 286 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 287 | GCC_WARN_UNUSED_FUNCTION = YES; 288 | GCC_WARN_UNUSED_VARIABLE = YES; 289 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 290 | MTL_ENABLE_DEBUG_INFO = NO; 291 | SDKROOT = iphoneos; 292 | TARGETED_DEVICE_FAMILY = "1,2"; 293 | VALIDATE_PRODUCT = YES; 294 | }; 295 | name = Release; 296 | }; 297 | 601067581E65AFFA00481C99 /* Debug */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 301 | INFOPLIST_FILE = "Runloop-性能优化,加载大图/Info.plist"; 302 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 303 | PRODUCT_BUNDLE_IDENTIFIER = "codepgq.git.Runloop----------"; 304 | PRODUCT_NAME = "$(TARGET_NAME)"; 305 | }; 306 | name = Debug; 307 | }; 308 | 601067591E65AFFA00481C99 /* Release */ = { 309 | isa = XCBuildConfiguration; 310 | buildSettings = { 311 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 312 | INFOPLIST_FILE = "Runloop-性能优化,加载大图/Info.plist"; 313 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 314 | PRODUCT_BUNDLE_IDENTIFIER = "codepgq.git.Runloop----------"; 315 | PRODUCT_NAME = "$(TARGET_NAME)"; 316 | }; 317 | name = Release; 318 | }; 319 | /* End XCBuildConfiguration section */ 320 | 321 | /* Begin XCConfigurationList section */ 322 | 6010673B1E65AFFA00481C99 /* Build configuration list for PBXProject "Runloop-性能优化,加载大图" */ = { 323 | isa = XCConfigurationList; 324 | buildConfigurations = ( 325 | 601067551E65AFFA00481C99 /* Debug */, 326 | 601067561E65AFFA00481C99 /* Release */, 327 | ); 328 | defaultConfigurationIsVisible = 0; 329 | defaultConfigurationName = Release; 330 | }; 331 | 601067571E65AFFA00481C99 /* Build configuration list for PBXNativeTarget "Runloop-性能优化,加载大图" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | 601067581E65AFFA00481C99 /* Debug */, 335 | 601067591E65AFFA00481C99 /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | /* End XCConfigurationList section */ 341 | }; 342 | rootObject = 601067381E65AFFA00481C99 /* Project object */; 343 | } 344 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codepgq/RunloopDemo/19722f0d94f0c151fd09d9f90d24bc40f4e2e22f/Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/.DS_Store -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // Runloop-性能优化,加载大图 4 | // 5 | // Created by codepgq on 2017/2/28. 6 | // Copyright © 2017年 pgq. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // Runloop-性能优化,加载大图 4 | // 5 | // Created by codepgq on 2017/2/28. 6 | // Copyright © 2017年 pgq. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 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 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/RunloopClass/PQRunloop.h: -------------------------------------------------------------------------------- 1 | // 2 | // PQRunloop.h 3 | // Runloop-性能优化,加载大图 4 | // 5 | // Created by codepgq on 2017/3/1. 6 | // Copyright © 2017年 pgq. All rights reserved. 7 | // 8 | 9 | /* 10 | 为什么要优化: 11 | Runloop会在一次循环中绘制屏幕上所有的点,如果加载的图片过大,过多,就会造成需要绘制很多的 12 | 的点,导致一次循环的时间过长,从而导致UI卡顿。 13 | */ 14 | 15 | #import 16 | #import "PQSingle.h" 17 | typedef BOOL(^RunloopBlock)(void); 18 | @interface PQRunloop : NSObject 19 | PQSINGLE_H(Instance) 20 | //最大任务加载数 默认18(这里主要看屏幕能显示最多少个图片来确定) 21 | @property (nonatomic,assign) NSUInteger maxQueue; 22 | //添加任务 23 | - (void)addTask:(RunloopBlock)unit withId:(id)key; 24 | //移除所有任务 25 | - (void)removeAllTasks; 26 | @end 27 | 28 | 29 | //动态添加属性 30 | @interface UITableViewCell (PQRunloop) 31 | 32 | @property (nonatomic, strong) NSIndexPath *willShowIndexpath; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/RunloopClass/PQRunloop.m: -------------------------------------------------------------------------------- 1 | // 2 | // PQRunloop.m 3 | // Runloop-性能优化,加载大图 4 | // 5 | // Created by codepgq on 2017/3/1. 6 | // Copyright © 2017年 pgq. All rights reserved. 7 | // 8 | 9 | #import "PQRunloop.h" 10 | #import 11 | 12 | @interface PQRunloop () 13 | //定时器 这里定时器里面不要进行操作,否则可能会导致反优化(如果处理了耗时操作,电池电量也会加快) 14 | @property (nonatomic,strong) NSTimer * timer; 15 | //任务数组 16 | @property (nonatomic,strong) NSMutableArray * tasks; 17 | //任务的keys 18 | @property (nonatomic,strong) NSMutableArray * taskKeys; 19 | 20 | @end 21 | 22 | @implementation PQRunloop 23 | PQSINGLE_M(Instance) 24 | 25 | - (instancetype)init 26 | { 27 | self = [super init]; 28 | if (self) { 29 | //初始化对象/基本信息 30 | self.maxQueue = 18; 31 | self.tasks = [NSMutableArray array]; 32 | self.taskKeys = [NSMutableArray array]; 33 | self.timer = [NSTimer scheduledTimerWithTimeInterval:0.001 repeats:YES block:^(NSTimer * _Nonnull timer) { }]; 34 | //添加Runloop观察者 35 | [self addRunloopObserver]; 36 | } 37 | return self; 38 | } 39 | 40 | //删除所有任务 41 | - (void)removeAllTasks{ 42 | [self.taskKeys removeAllObjects]; 43 | [self.tasks removeAllObjects]; 44 | } 45 | 46 | //add task 添加任务 47 | - (void)addTask:(RunloopBlock)unit withId:(id)key{ 48 | //添加任务到数组 49 | [self.tasks addObject:unit]; 50 | [self.taskKeys addObject:key]; 51 | 52 | //为了保证加载到图片最大数是18所以要删除 53 | if (self.tasks.count > self.maxQueue) { 54 | [self.tasks removeObjectAtIndex:0]; 55 | [self.taskKeys removeObjectAtIndex:0]; 56 | } 57 | } 58 | 59 | //这里处理耗时操作了 60 | static void Callback(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info){ 61 | 62 | //通过info桥接为当前的对象 63 | PQRunloop * runloop = (__bridge PQRunloop *)info; 64 | 65 | //如果没有任务,就直接返回 66 | if (runloop.tasks.count == 0) { 67 | return; 68 | } 69 | 70 | BOOL result = NO; 71 | while (result == NO && runloop.tasks.count) { 72 | 73 | //取出任务 74 | RunloopBlock unit = runloop.tasks.firstObject; 75 | 76 | //执行任务 77 | result = unit(); 78 | 79 | //删除任务 80 | [runloop.tasks removeObjectAtIndex:0]; 81 | } 82 | } 83 | 84 | //添加runloop监听者 85 | - (void)addRunloopObserver{ 86 | 87 | // 获取 当前的Runloop ref - 指针 88 | CFRunLoopRef current = CFRunLoopGetCurrent(); 89 | 90 | //定义一个RunloopObserver 91 | CFRunLoopObserverRef defaultModeObserver; 92 | 93 | //上下文 94 | /* 95 | typedef struct { 96 | CFIndex version; //版本号 long 97 | void * info; //这里我们要填写对象(self或者传进来的对象) 98 | const void *(*retain)(const void *info); //填写&CFRetain 99 | void (*release)(const void *info); //填写&CGFRelease 100 | CFStringRef (*copyDescription)(const void *info); //NULL 101 | } CFRunLoopObserverContext; 102 | */ 103 | CFRunLoopObserverContext context = { 104 | 0, 105 | (__bridge void *)(self), 106 | &CFRetain, 107 | &CFRelease, 108 | NULL 109 | }; 110 | 111 | /* 112 | 1 NULL空指针 nil空对象 这里填写NULL 113 | 2 模式 114 | kCFRunLoopEntry = (1UL << 0), 115 | kCFRunLoopBeforeTimers = (1UL << 1), 116 | kCFRunLoopBeforeSources = (1UL << 2), 117 | kCFRunLoopBeforeWaiting = (1UL << 5), 118 | kCFRunLoopAfterWaiting = (1UL << 6), 119 | kCFRunLoopExit = (1UL << 7), 120 | kCFRunLoopAllActivities = 0x0FFFFFFFU 121 | 3 是否重复 - YES 122 | 4 nil 或者 NSIntegerMax - 999 123 | 5 回调 124 | 6 上下文 125 | */ 126 | // 创建观察者 127 | defaultModeObserver = CFRunLoopObserverCreate(NULL, 128 | kCFRunLoopBeforeWaiting, YES, 129 | NSIntegerMax - 999, 130 | &Callback, 131 | &context); 132 | 133 | //添加当前runloop的观察着 134 | CFRunLoopAddObserver(current, defaultModeObserver, kCFRunLoopDefaultMode); 135 | 136 | //释放 137 | CFRelease(defaultModeObserver); 138 | } 139 | 140 | @end 141 | 142 | 143 | //动态添加属性 144 | @implementation UITableViewCell (PQRunloop) 145 | 146 | - (NSIndexPath *)willShowIndexpath { 147 | NSIndexPath *indexPath = objc_getAssociatedObject(self, @selector(willShowIndexpath)); 148 | return indexPath; 149 | } 150 | 151 | - (void)setWillShowIndexpath:(NSIndexPath *)willShowIndexpath{ 152 | objc_setAssociatedObject(self, @selector(willShowIndexpath), willShowIndexpath, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 153 | } 154 | 155 | @end 156 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/RunloopClass/PQSingle.h: -------------------------------------------------------------------------------- 1 | // 2 | // PQSingle.h 3 | // SingleClassDemo 4 | // 5 | // Created by Mac on 16/12/21. 6 | // Copyright © 2016年 Mac. All rights reserved. 7 | // 8 | 9 | #ifndef PQSingle_h 10 | #define PQSingle_h 11 | 12 | #define PQSINGLE_H(name) +(instancetype)share##name; 13 | 14 | #if __has_feature(objc_arc) 15 | 16 | #define PQSINGLE_M(name) static id _singleManager = nil;\ 17 | + (instancetype)share##name{\ 18 | static dispatch_once_t onceToken;\ 19 | dispatch_once(&onceToken, ^{\ 20 | _singleManager = [[self alloc] init];\ 21 | });\ 22 | return _singleManager;\ 23 | }\ 24 | \ 25 | + (instancetype)allocWithZone:(struct _NSZone *)zone{\ 26 | static dispatch_once_t onceToken;\ 27 | dispatch_once(&onceToken, ^{\ 28 | _singleManager = [super allocWithZone:zone];\ 29 | });\ 30 | return _singleManager;\ 31 | }\ 32 | \ 33 | - (id)mutableCopy{\ 34 | return _singleManager;\ 35 | }\ 36 | \ 37 | - (id)copy{\ 38 | return _singleManager;\ 39 | } 40 | 41 | #else 42 | 43 | #define PQSINGLE_M(name) static id _singleManager = nil;\ 44 | + (instancetype)share##name{\ 45 | return [[self alloc]init];\ 46 | }\ 47 | \ 48 | + (instancetype)allocWithZone:(struct _NSZone *)zone{\ 49 | static dispatch_once_t onceToken;\ 50 | dispatch_once(&onceToken, ^{\ 51 | _singleManager = [super allocWithZone:zone];\ 52 | });\ 53 | return _singleManager;\ 54 | }\ 55 | \ 56 | - (id)mutableCopy{\ 57 | return _singleManager;\ 58 | }\ 59 | \ 60 | - (id)copy{\ 61 | return _singleManager;\ 62 | }\ 63 | - (oneway void)release{\ 64 | }\ 65 | \ 66 | - (instancetype)retain{\ 67 | return _singleManager;\ 68 | }\ 69 | \ 70 | - (NSUInteger)retainCount{\ 71 | return 9999;\ 72 | }\ 73 | 74 | #endif 75 | 76 | #endif /* PQSingle_h */ 77 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/RunloopClass/Utils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Utils.h 3 | // Runloop-性能优化,加载大图 4 | // 5 | // Created by codepgq on 2017/3/1. 6 | // Copyright © 2017年 pgq. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Utils : NSObject 12 | 13 | /** 14 | 创建ImageView的工厂 15 | 16 | @param frame 大小位置 17 | @param tag tag值,用于移除 18 | @return UIImageView 19 | */ 20 | + (UIImageView*)createImageWithFrame:(CGRect)frame tag:(NSInteger)tag; 21 | 22 | 23 | /** 24 | 创建Label的工厂 25 | 26 | @param frame 大小位置 27 | @param tag tag值,用于移除 28 | @param text 文本内容 29 | @param color 文本颜色 30 | @return UILabel 31 | */ 32 | + (UILabel *)createLabelWithFrame:(CGRect)frame tag:(NSInteger)tag text:(NSString *)text textColor:(UIColor *)color; 33 | @end 34 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/RunloopClass/Utils.m: -------------------------------------------------------------------------------- 1 | // 2 | // Utils.m 3 | // Runloop-性能优化,加载大图 4 | // 5 | // Created by codepgq on 2017/3/1. 6 | // Copyright © 2017年 pgq. All rights reserved. 7 | // 8 | 9 | #import "Utils.h" 10 | 11 | @implementation Utils 12 | 13 | + (UIImageView*)createImageWithFrame:(CGRect)frame tag:(NSInteger)tag{ 14 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame]; 15 | imageView.tag = tag; 16 | NSString *path = [[NSBundle mainBundle] pathForResource:@"spaceship" ofType:@"jpg"]; 17 | UIImage *image = [UIImage imageWithContentsOfFile:path]; 18 | imageView.contentMode = UIViewContentModeScaleAspectFit; 19 | imageView.image = image; 20 | return imageView; 21 | } 22 | 23 | + (UILabel *)createLabelWithFrame:(CGRect)frame tag:(NSInteger)tag text:(NSString *)text textColor:(UIColor *)color{ 24 | UILabel *label = [[UILabel alloc] initWithFrame:frame]; 25 | label.backgroundColor = [UIColor clearColor]; 26 | label.textColor = color; 27 | label.text = text; 28 | label.font = [UIFont boldSystemFontOfSize:13]; 29 | label.tag = tag; 30 | label.numberOfLines = 0; 31 | return label; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // Runloop-性能优化,加载大图 4 | // 5 | // Created by codepgq on 2017/2/28. 6 | // Copyright © 2017年 pgq. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // Runloop-性能优化,加载大图 4 | // 5 | // Created by codepgq on 2017/2/28. 6 | // Copyright © 2017年 pgq. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | /* 11 | 思想: 12 | 1 加载图片的代码保存起来,不要直接执行,用一个数组保存 13 | block 14 | 2 监听我们的Runloop循环 15 | CFRunloop CFRunloopObserver 16 | 3 每次Runloop循环就让它从数组里面去一个加载图片等任务出来执行 17 | */ 18 | 19 | #import "PQRunloop.h" 20 | #import "Utils.h" 21 | @interface ViewController () 22 | @property (weak, nonatomic) IBOutlet UITableView *tableView; 23 | @end 24 | 25 | static NSString * const CellIdentifier = @"CellIdentifier"; 26 | @implementation ViewController 27 | 28 | - (void)viewDidLoad { 29 | [super viewDidLoad]; 30 | //提前注册cell 31 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier]; 32 | } 33 | 34 | - (void)didReceiveMemoryWarning { 35 | [super didReceiveMemoryWarning]; 36 | [[PQRunloop shareInstance] removeAllTasks]; 37 | } 38 | 39 | #pragma MARK - Talbeview Delegate 40 | 41 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 42 | return 100; 43 | } 44 | 45 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 46 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 47 | //先赋值将要显示的indexPath 48 | cell.willShowIndexpath = indexPath; 49 | 50 | //先移除 51 | for (NSInteger i = 1; i <= 5; i++) { 52 | [[cell.contentView viewWithTag:i] removeFromSuperview]; 53 | } 54 | //添加文字 55 | [ViewController addLabel:cell indexPath:indexPath]; 56 | 57 | #if 0 //是否开启Runloop优化 58 | 59 | // 使用优化 60 | [[PQRunloop shareInstance] addTask:^BOOL{ 61 | if (![cell.willShowIndexpath isEqual:indexPath]) { 62 | return NO; 63 | } 64 | [ViewController addCenterImg:cell]; 65 | return YES; 66 | } withId:indexPath]; 67 | 68 | [[PQRunloop shareInstance] addTask:^BOOL{ 69 | if (![cell.willShowIndexpath isEqual:indexPath]) { 70 | return NO; 71 | } 72 | [ViewController addRightImg:cell]; 73 | return YES; 74 | } withId:indexPath]; 75 | 76 | [[PQRunloop shareInstance] addTask:^BOOL{ 77 | if (![cell.willShowIndexpath isEqual:indexPath]) { 78 | return NO; 79 | } 80 | [ViewController addLeftImg:cell indexPath:indexPath]; 81 | return YES; 82 | } withId:indexPath]; 83 | #else 84 | // 不使用优化 85 | [ViewController addCenterImg:cell]; 86 | [ViewController addRightImg:cell]; 87 | [ViewController addLeftImg:cell indexPath:indexPath]; 88 | 89 | #endif 90 | return cell; 91 | } 92 | 93 | 94 | /** 95 | 添加View到ContentView中,使用CoreAnimation动画 96 | 97 | @param cell cell 98 | @param view 需要加入的View 99 | */ 100 | + (void)addViewWith:(UITableViewCell *)cell view:(UIView *)view{ 101 | [UIView transitionWithView:cell.contentView duration:0.3 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionTransitionCrossDissolve animations:^{ 102 | [cell.contentView addSubview:view]; 103 | } completion:^(BOOL finished) { 104 | }]; 105 | } 106 | 107 | 108 | /** 109 | 创建一个Label 110 | 111 | @param cell cell 112 | @param indexPath 用来拼接 113 | */ 114 | + (void)addLabel:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath { 115 | NSString * text = [NSString stringWithFormat:@"%zd - Runloop性能优化:一次绘制一张图片。", indexPath.row]; 116 | UILabel *label = [Utils createLabelWithFrame:CGRectMake(5, 5, 300, 25) tag:1 text:text textColor:[UIColor orangeColor]]; 117 | 118 | [cell.contentView addSubview:label]; 119 | } 120 | 121 | 122 | /** 123 | 添加中间图片 124 | 125 | @param cell cell 126 | */ 127 | + (void)addCenterImg:(UITableViewCell *)cell{ 128 | UIImageView *imageView = [Utils createImageWithFrame:CGRectMake(105, 20, 85, 85) tag:2]; 129 | [self addViewWith:cell view:imageView]; 130 | } 131 | 132 | 133 | /** 134 | 添加右边图片 135 | 136 | @param cell cell 137 | */ 138 | + (void)addRightImg:(UITableViewCell *)cell{ 139 | UIImageView *imageView = [Utils createImageWithFrame:CGRectMake(200, 20, 85, 85) tag:3]; 140 | [self addViewWith:cell view:imageView]; 141 | } 142 | 143 | 144 | /** 145 | 添加左边图片和 label 146 | 147 | @param cell cell 148 | @param indexPath 用来拼接字符串使用 149 | */ 150 | + (void)addLeftImg:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath { 151 | NSString *text = [NSString stringWithFormat:@"%zd - 在Runloop中一次循环绘制所有的点,这里显示加载大图,使得绘制的点增多,从而导致Runloop的点一次循环时间增长,从而导致UI卡顿。", indexPath.row]; 152 | 153 | UILabel *label = [Utils createLabelWithFrame:CGRectMake(5, 99, [UIScreen mainScreen].bounds.size.width - 10, 50) tag:4 text:text textColor:[UIColor colorWithRed:0.2 green:100.f/255.f blue:0 alpha:1]]; 154 | 155 | UIImageView *imageView = [Utils createImageWithFrame:CGRectMake(5, 20, 85, 85) tag:5]; 156 | [self addViewWith:cell view:label]; 157 | [self addViewWith:cell view:imageView]; 158 | } 159 | 160 | @end 161 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Runloop-性能优化,加载大图 4 | // 5 | // Created by codepgq on 2017/2/28. 6 | // Copyright © 2017年 pgq. 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 | -------------------------------------------------------------------------------- /Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/spaceship.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codepgq/RunloopDemo/19722f0d94f0c151fd09d9f90d24bc40f4e2e22f/Runloop-性能优化,加载大图/Runloop-性能优化,加载大图/spaceship.jpg --------------------------------------------------------------------------------