├── .gitignore ├── MVScrollViewAutoLayout.xcodeproj └── project.pbxproj ├── MVScrollViewAutoLayout.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── MVScrollViewAutoLayout.xccheckout ├── Podfile ├── README.md ├── ScrollViewAutoLayout ├── AppDelegate.h ├── AppDelegate.m ├── AutoLayoutViewController.h ├── AutoLayoutViewController.m ├── Base.lproj │ ├── Main_iPad.storyboard │ └── Main_iPhone.storyboard ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── LayoutUtils.h ├── LayoutUtils.m ├── MVScrollViewAutoLayout-Info.plist ├── MVScrollViewAutoLayout-Prefix.pch ├── SpringsAndStroutsViewController.h ├── SpringsAndStroutsViewController.m ├── en.lproj │ └── InfoPlist.strings └── main.m └── auto-layout-scroll-view-preview.png /.gitignore: -------------------------------------------------------------------------------- 1 | # 3rdparty stuff 2 | ###################### 3 | scratch/ 4 | 5 | # OS generated files 6 | ###################### 7 | .DS_Store 8 | .DS_Store? 9 | .Spotlight-V100 10 | .Transhes 11 | 12 | # Xcode 13 | ################################ 14 | *.pbxuser 15 | *.mode1v3 16 | *.mode2v3 17 | *.perspectivev3 18 | *.xcuserstate 19 | project.xcworkspace 20 | xcuserdata/ 21 | 22 | # IntelliJ Idea 23 | ############################### 24 | *.iws 25 | workspace.xml 26 | tasks.xml 27 | 28 | # cocoapods 29 | ############################### 30 | Pods/ 31 | Podfile.lock 32 | 33 | 34 | # emacs 35 | ############################### 36 | *~ 37 | -------------------------------------------------------------------------------- /MVScrollViewAutoLayout.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 31FE580AE4A546E89D1295D8 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6038E9FFA0A94B3B94030F14 /* libPods.a */; }; 11 | 65921F9217FC6F3700F63767 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65921F9117FC6F3700F63767 /* Foundation.framework */; }; 12 | 65921F9417FC6F3700F63767 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65921F9317FC6F3700F63767 /* CoreGraphics.framework */; }; 13 | 65921F9617FC6F3700F63767 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65921F9517FC6F3700F63767 /* UIKit.framework */; }; 14 | 65921F9C17FC6F3700F63767 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 65921F9A17FC6F3700F63767 /* InfoPlist.strings */; }; 15 | 65921F9E17FC6F3700F63767 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 65921F9D17FC6F3700F63767 /* main.m */; }; 16 | 65921FA217FC6F3700F63767 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 65921FA117FC6F3700F63767 /* AppDelegate.m */; }; 17 | 65921FA517FC6F3800F63767 /* Main_iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65921FA317FC6F3800F63767 /* Main_iPhone.storyboard */; }; 18 | 65921FA817FC6F3800F63767 /* Main_iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65921FA617FC6F3800F63767 /* Main_iPad.storyboard */; }; 19 | 65921FAB17FC6F3800F63767 /* AutoLayoutViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 65921FAA17FC6F3800F63767 /* AutoLayoutViewController.m */; }; 20 | 65921FAD17FC6F3800F63767 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65921FAC17FC6F3800F63767 /* Images.xcassets */; }; 21 | 65921FF417FD5E5D00F63767 /* LayoutUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 65921FF317FD5E5D00F63767 /* LayoutUtils.m */; }; 22 | ABC350FD9E74DA66BD559C30 /* SpringsAndStroutsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ABC3507560A79A4852059629 /* SpringsAndStroutsViewController.m */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 16BCE0E859964CD3B22D9A70 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; 27 | 6038E9FFA0A94B3B94030F14 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 65921F8E17FC6F3700F63767 /* MVScrollViewAutoLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MVScrollViewAutoLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | 65921F9117FC6F3700F63767 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 30 | 65921F9317FC6F3700F63767 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 31 | 65921F9517FC6F3700F63767 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 32 | 65921F9917FC6F3700F63767 /* MVScrollViewAutoLayout-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MVScrollViewAutoLayout-Info.plist"; sourceTree = ""; }; 33 | 65921F9B17FC6F3700F63767 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 34 | 65921F9D17FC6F3700F63767 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | 65921F9F17FC6F3700F63767 /* MVScrollViewAutoLayout-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MVScrollViewAutoLayout-Prefix.pch"; sourceTree = ""; }; 36 | 65921FA017FC6F3700F63767 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 37 | 65921FA117FC6F3700F63767 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 38 | 65921FA417FC6F3800F63767 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main_iPhone.storyboard; sourceTree = ""; }; 39 | 65921FA717FC6F3800F63767 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main_iPad.storyboard; sourceTree = ""; }; 40 | 65921FA917FC6F3800F63767 /* AutoLayoutViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AutoLayoutViewController.h; sourceTree = ""; }; 41 | 65921FAA17FC6F3800F63767 /* AutoLayoutViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AutoLayoutViewController.m; sourceTree = ""; }; 42 | 65921FAC17FC6F3800F63767 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 43 | 65921FB317FC6F3800F63767 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 44 | 65921FF217FD5E5D00F63767 /* LayoutUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutUtils.h; sourceTree = ""; }; 45 | 65921FF317FD5E5D00F63767 /* LayoutUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LayoutUtils.m; sourceTree = ""; }; 46 | ABC3507560A79A4852059629 /* SpringsAndStroutsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpringsAndStroutsViewController.m; sourceTree = ""; }; 47 | ABC35EBEBC81E0FEC45B7325 /* SpringsAndStroutsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpringsAndStroutsViewController.h; sourceTree = ""; }; 48 | /* End PBXFileReference section */ 49 | 50 | /* Begin PBXFrameworksBuildPhase section */ 51 | 65921F8B17FC6F3700F63767 /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | 65921F9417FC6F3700F63767 /* CoreGraphics.framework in Frameworks */, 56 | 65921F9617FC6F3700F63767 /* UIKit.framework in Frameworks */, 57 | 65921F9217FC6F3700F63767 /* Foundation.framework in Frameworks */, 58 | 31FE580AE4A546E89D1295D8 /* libPods.a in Frameworks */, 59 | ); 60 | runOnlyForDeploymentPostprocessing = 0; 61 | }; 62 | /* End PBXFrameworksBuildPhase section */ 63 | 64 | /* Begin PBXGroup section */ 65 | 65921F8517FC6F3700F63767 = { 66 | isa = PBXGroup; 67 | children = ( 68 | 65921F9717FC6F3700F63767 /* ScrollViewAutoLayout */, 69 | 65921F9017FC6F3700F63767 /* Frameworks */, 70 | 65921F8F17FC6F3700F63767 /* Products */, 71 | 16BCE0E859964CD3B22D9A70 /* Pods.xcconfig */, 72 | ); 73 | sourceTree = ""; 74 | }; 75 | 65921F8F17FC6F3700F63767 /* Products */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 65921F8E17FC6F3700F63767 /* MVScrollViewAutoLayout.app */, 79 | ); 80 | name = Products; 81 | sourceTree = ""; 82 | }; 83 | 65921F9017FC6F3700F63767 /* Frameworks */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 65921F9117FC6F3700F63767 /* Foundation.framework */, 87 | 65921F9317FC6F3700F63767 /* CoreGraphics.framework */, 88 | 65921F9517FC6F3700F63767 /* UIKit.framework */, 89 | 65921FB317FC6F3800F63767 /* XCTest.framework */, 90 | 6038E9FFA0A94B3B94030F14 /* libPods.a */, 91 | ); 92 | name = Frameworks; 93 | sourceTree = ""; 94 | }; 95 | 65921F9717FC6F3700F63767 /* ScrollViewAutoLayout */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 65921FA017FC6F3700F63767 /* AppDelegate.h */, 99 | 65921FA117FC6F3700F63767 /* AppDelegate.m */, 100 | 65921FA317FC6F3800F63767 /* Main_iPhone.storyboard */, 101 | 65921FA617FC6F3800F63767 /* Main_iPad.storyboard */, 102 | 65921FA917FC6F3800F63767 /* AutoLayoutViewController.h */, 103 | 65921FAA17FC6F3800F63767 /* AutoLayoutViewController.m */, 104 | ABC3507560A79A4852059629 /* SpringsAndStroutsViewController.m */, 105 | ABC35EBEBC81E0FEC45B7325 /* SpringsAndStroutsViewController.h */, 106 | 65921FF217FD5E5D00F63767 /* LayoutUtils.h */, 107 | 65921FF317FD5E5D00F63767 /* LayoutUtils.m */, 108 | 65921FAC17FC6F3800F63767 /* Images.xcassets */, 109 | 65921F9817FC6F3700F63767 /* Supporting Files */, 110 | ); 111 | path = ScrollViewAutoLayout; 112 | sourceTree = ""; 113 | }; 114 | 65921F9817FC6F3700F63767 /* Supporting Files */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | 65921F9917FC6F3700F63767 /* MVScrollViewAutoLayout-Info.plist */, 118 | 65921F9A17FC6F3700F63767 /* InfoPlist.strings */, 119 | 65921F9D17FC6F3700F63767 /* main.m */, 120 | 65921F9F17FC6F3700F63767 /* MVScrollViewAutoLayout-Prefix.pch */, 121 | ); 122 | name = "Supporting Files"; 123 | sourceTree = ""; 124 | }; 125 | /* End PBXGroup section */ 126 | 127 | /* Begin PBXNativeTarget section */ 128 | 65921F8D17FC6F3700F63767 /* MVScrollViewAutoLayout */ = { 129 | isa = PBXNativeTarget; 130 | buildConfigurationList = 65921FC317FC6F3800F63767 /* Build configuration list for PBXNativeTarget "MVScrollViewAutoLayout" */; 131 | buildPhases = ( 132 | 0625C099ACFA42798AAFB469 /* Check Pods Manifest.lock */, 133 | 65921F8A17FC6F3700F63767 /* Sources */, 134 | 65921F8B17FC6F3700F63767 /* Frameworks */, 135 | 65921F8C17FC6F3700F63767 /* Resources */, 136 | 907497539D8348FD81FC0F83 /* Copy Pods Resources */, 137 | ); 138 | buildRules = ( 139 | ); 140 | dependencies = ( 141 | ); 142 | name = MVScrollViewAutoLayout; 143 | productName = ScrollViewAutoLayout; 144 | productReference = 65921F8E17FC6F3700F63767 /* MVScrollViewAutoLayout.app */; 145 | productType = "com.apple.product-type.application"; 146 | }; 147 | /* End PBXNativeTarget section */ 148 | 149 | /* Begin PBXProject section */ 150 | 65921F8617FC6F3700F63767 /* Project object */ = { 151 | isa = PBXProject; 152 | attributes = { 153 | LastUpgradeCheck = 0500; 154 | ORGANIZATIONNAME = Snupps; 155 | }; 156 | buildConfigurationList = 65921F8917FC6F3700F63767 /* Build configuration list for PBXProject "MVScrollViewAutoLayout" */; 157 | compatibilityVersion = "Xcode 3.2"; 158 | developmentRegion = English; 159 | hasScannedForEncodings = 0; 160 | knownRegions = ( 161 | en, 162 | Base, 163 | ); 164 | mainGroup = 65921F8517FC6F3700F63767; 165 | productRefGroup = 65921F8F17FC6F3700F63767 /* Products */; 166 | projectDirPath = ""; 167 | projectRoot = ""; 168 | targets = ( 169 | 65921F8D17FC6F3700F63767 /* MVScrollViewAutoLayout */, 170 | ); 171 | }; 172 | /* End PBXProject section */ 173 | 174 | /* Begin PBXResourcesBuildPhase section */ 175 | 65921F8C17FC6F3700F63767 /* Resources */ = { 176 | isa = PBXResourcesBuildPhase; 177 | buildActionMask = 2147483647; 178 | files = ( 179 | 65921FA817FC6F3800F63767 /* Main_iPad.storyboard in Resources */, 180 | 65921FAD17FC6F3800F63767 /* Images.xcassets in Resources */, 181 | 65921FA517FC6F3800F63767 /* Main_iPhone.storyboard in Resources */, 182 | 65921F9C17FC6F3700F63767 /* InfoPlist.strings in Resources */, 183 | ); 184 | runOnlyForDeploymentPostprocessing = 0; 185 | }; 186 | /* End PBXResourcesBuildPhase section */ 187 | 188 | /* Begin PBXShellScriptBuildPhase section */ 189 | 0625C099ACFA42798AAFB469 /* Check Pods Manifest.lock */ = { 190 | isa = PBXShellScriptBuildPhase; 191 | buildActionMask = 2147483647; 192 | files = ( 193 | ); 194 | inputPaths = ( 195 | ); 196 | name = "Check Pods Manifest.lock"; 197 | outputPaths = ( 198 | ); 199 | runOnlyForDeploymentPostprocessing = 0; 200 | shellPath = /bin/sh; 201 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 202 | showEnvVarsInLog = 0; 203 | }; 204 | 907497539D8348FD81FC0F83 /* Copy Pods Resources */ = { 205 | isa = PBXShellScriptBuildPhase; 206 | buildActionMask = 2147483647; 207 | files = ( 208 | ); 209 | inputPaths = ( 210 | ); 211 | name = "Copy Pods Resources"; 212 | outputPaths = ( 213 | ); 214 | runOnlyForDeploymentPostprocessing = 0; 215 | shellPath = /bin/sh; 216 | shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n"; 217 | showEnvVarsInLog = 0; 218 | }; 219 | /* End PBXShellScriptBuildPhase section */ 220 | 221 | /* Begin PBXSourcesBuildPhase section */ 222 | 65921F8A17FC6F3700F63767 /* Sources */ = { 223 | isa = PBXSourcesBuildPhase; 224 | buildActionMask = 2147483647; 225 | files = ( 226 | 65921FF417FD5E5D00F63767 /* LayoutUtils.m in Sources */, 227 | 65921FAB17FC6F3800F63767 /* AutoLayoutViewController.m in Sources */, 228 | 65921FA217FC6F3700F63767 /* AppDelegate.m in Sources */, 229 | 65921F9E17FC6F3700F63767 /* main.m in Sources */, 230 | ABC350FD9E74DA66BD559C30 /* SpringsAndStroutsViewController.m in Sources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | /* End PBXSourcesBuildPhase section */ 235 | 236 | /* Begin PBXVariantGroup section */ 237 | 65921F9A17FC6F3700F63767 /* InfoPlist.strings */ = { 238 | isa = PBXVariantGroup; 239 | children = ( 240 | 65921F9B17FC6F3700F63767 /* en */, 241 | ); 242 | name = InfoPlist.strings; 243 | sourceTree = ""; 244 | }; 245 | 65921FA317FC6F3800F63767 /* Main_iPhone.storyboard */ = { 246 | isa = PBXVariantGroup; 247 | children = ( 248 | 65921FA417FC6F3800F63767 /* Base */, 249 | ); 250 | name = Main_iPhone.storyboard; 251 | sourceTree = ""; 252 | }; 253 | 65921FA617FC6F3800F63767 /* Main_iPad.storyboard */ = { 254 | isa = PBXVariantGroup; 255 | children = ( 256 | 65921FA717FC6F3800F63767 /* Base */, 257 | ); 258 | name = Main_iPad.storyboard; 259 | sourceTree = ""; 260 | }; 261 | /* End PBXVariantGroup section */ 262 | 263 | /* Begin XCBuildConfiguration section */ 264 | 65921FC117FC6F3800F63767 /* Debug */ = { 265 | isa = XCBuildConfiguration; 266 | buildSettings = { 267 | ALWAYS_SEARCH_USER_PATHS = NO; 268 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 269 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 270 | CLANG_CXX_LIBRARY = "libc++"; 271 | CLANG_ENABLE_MODULES = YES; 272 | CLANG_ENABLE_OBJC_ARC = YES; 273 | CLANG_WARN_BOOL_CONVERSION = YES; 274 | CLANG_WARN_CONSTANT_CONVERSION = YES; 275 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 276 | CLANG_WARN_EMPTY_BODY = YES; 277 | CLANG_WARN_ENUM_CONVERSION = YES; 278 | CLANG_WARN_INT_CONVERSION = YES; 279 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 280 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 281 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 282 | COPY_PHASE_STRIP = NO; 283 | GCC_C_LANGUAGE_STANDARD = gnu99; 284 | GCC_DYNAMIC_NO_PIC = NO; 285 | GCC_OPTIMIZATION_LEVEL = 0; 286 | GCC_PREPROCESSOR_DEFINITIONS = ( 287 | "DEBUG=1", 288 | "$(inherited)", 289 | ); 290 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 291 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 292 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 293 | GCC_WARN_UNDECLARED_SELECTOR = YES; 294 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 295 | GCC_WARN_UNUSED_FUNCTION = YES; 296 | GCC_WARN_UNUSED_VARIABLE = YES; 297 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 298 | ONLY_ACTIVE_ARCH = YES; 299 | SDKROOT = iphoneos; 300 | TARGETED_DEVICE_FAMILY = "1,2"; 301 | }; 302 | name = Debug; 303 | }; 304 | 65921FC217FC6F3800F63767 /* Release */ = { 305 | isa = XCBuildConfiguration; 306 | buildSettings = { 307 | ALWAYS_SEARCH_USER_PATHS = NO; 308 | ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; 309 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 310 | CLANG_CXX_LIBRARY = "libc++"; 311 | CLANG_ENABLE_MODULES = YES; 312 | CLANG_ENABLE_OBJC_ARC = YES; 313 | CLANG_WARN_BOOL_CONVERSION = YES; 314 | CLANG_WARN_CONSTANT_CONVERSION = YES; 315 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 316 | CLANG_WARN_EMPTY_BODY = YES; 317 | CLANG_WARN_ENUM_CONVERSION = YES; 318 | CLANG_WARN_INT_CONVERSION = YES; 319 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 320 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 321 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 322 | COPY_PHASE_STRIP = YES; 323 | ENABLE_NS_ASSERTIONS = NO; 324 | GCC_C_LANGUAGE_STANDARD = gnu99; 325 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 326 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 327 | GCC_WARN_UNDECLARED_SELECTOR = YES; 328 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 329 | GCC_WARN_UNUSED_FUNCTION = YES; 330 | GCC_WARN_UNUSED_VARIABLE = YES; 331 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 332 | SDKROOT = iphoneos; 333 | TARGETED_DEVICE_FAMILY = "1,2"; 334 | VALIDATE_PRODUCT = YES; 335 | }; 336 | name = Release; 337 | }; 338 | 65921FC417FC6F3800F63767 /* Debug */ = { 339 | isa = XCBuildConfiguration; 340 | baseConfigurationReference = 16BCE0E859964CD3B22D9A70 /* Pods.xcconfig */; 341 | buildSettings = { 342 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 343 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 344 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 345 | GCC_PREFIX_HEADER = "ScrollViewAutoLayout/MVScrollViewAutoLayout-Prefix.pch"; 346 | INFOPLIST_FILE = "ScrollViewAutoLayout/MVScrollViewAutoLayout-Info.plist"; 347 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 348 | PRODUCT_NAME = MVScrollViewAutoLayout; 349 | WRAPPER_EXTENSION = app; 350 | }; 351 | name = Debug; 352 | }; 353 | 65921FC517FC6F3800F63767 /* Release */ = { 354 | isa = XCBuildConfiguration; 355 | baseConfigurationReference = 16BCE0E859964CD3B22D9A70 /* Pods.xcconfig */; 356 | buildSettings = { 357 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 358 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 359 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 360 | GCC_PREFIX_HEADER = "ScrollViewAutoLayout/MVScrollViewAutoLayout-Prefix.pch"; 361 | INFOPLIST_FILE = "ScrollViewAutoLayout/MVScrollViewAutoLayout-Info.plist"; 362 | IPHONEOS_DEPLOYMENT_TARGET = 6.0; 363 | PRODUCT_NAME = MVScrollViewAutoLayout; 364 | WRAPPER_EXTENSION = app; 365 | }; 366 | name = Release; 367 | }; 368 | /* End XCBuildConfiguration section */ 369 | 370 | /* Begin XCConfigurationList section */ 371 | 65921F8917FC6F3700F63767 /* Build configuration list for PBXProject "MVScrollViewAutoLayout" */ = { 372 | isa = XCConfigurationList; 373 | buildConfigurations = ( 374 | 65921FC117FC6F3800F63767 /* Debug */, 375 | 65921FC217FC6F3800F63767 /* Release */, 376 | ); 377 | defaultConfigurationIsVisible = 0; 378 | defaultConfigurationName = Release; 379 | }; 380 | 65921FC317FC6F3800F63767 /* Build configuration list for PBXNativeTarget "MVScrollViewAutoLayout" */ = { 381 | isa = XCConfigurationList; 382 | buildConfigurations = ( 383 | 65921FC417FC6F3800F63767 /* Debug */, 384 | 65921FC517FC6F3800F63767 /* Release */, 385 | ); 386 | defaultConfigurationIsVisible = 0; 387 | defaultConfigurationName = Release; 388 | }; 389 | /* End XCConfigurationList section */ 390 | }; 391 | rootObject = 65921F8617FC6F3700F63767 /* Project object */; 392 | } 393 | -------------------------------------------------------------------------------- /MVScrollViewAutoLayout.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MVScrollViewAutoLayout.xcworkspace/xcshareddata/MVScrollViewAutoLayout.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | F267C329-AA12-4445-990F-38ABC622F004 9 | IDESourceControlProjectName 10 | MVScrollViewAutoLayout 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 068DA7F1-2182-40E2-B82C-5700CECD71A3 14 | https://github.com/bizz84/MVScrollViewAutoLayout.git 15 | 16 | IDESourceControlProjectPath 17 | MVScrollViewAutoLayout.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 068DA7F1-2182-40E2-B82C-5700CECD71A3 21 | .. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/bizz84/MVScrollViewAutoLayout.git 25 | IDESourceControlProjectVersion 26 | 110 27 | IDESourceControlProjectWCCIdentifier 28 | 068DA7F1-2182-40E2-B82C-5700CECD71A3 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 068DA7F1-2182-40E2-B82C-5700CECD71A3 36 | IDESourceControlWCCName 37 | MVScrollViewAutoLayout 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '6.0' 2 | 3 | pod 'Masonry', '0.2.4' 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | MVScrollViewAutoLayout 2 | ======================================================= 3 | 4 | Example iOS project showing how Auto-Layout can calculate the contentSize of a UIScrollView for you based on the constraints of the scroll view’s subviews. 5 | 6 | This example is based on [this tutorial](http://www.apeth.com/iOSBook/ch20.html), which uses Auto-Layout directly with Apple's [Visual Layout Language](https://developer.apple.com/library/mac/documentation/userexperience/conceptual/AutolayoutPG/Articles/formatLanguage.html). 7 | 8 | ![Auto-Layout preview](https://github.com/bizz84/MVScrollViewAutoLayout/raw/master/auto-layout-scroll-view-preview.png "Auto-Layout preview") 9 | 10 | ## Usage 11 | 12 | This project uses the iOS Masonry library to manage the Auto-Layout constraints. Before running the project, run the following: 13 | 14 | `pod install` 15 | 16 | ## Credits 17 | 18 | * [cloudkite / Masonry](https://github.com/cloudkite/Masonry) 19 | * [Programming iOS 6, by Matt Neuburg](http://shop.oreilly.com/product/0636920029717.do) 20 | 21 | ## License 22 | 23 | Copyright (c) 2013 Andrea Bizzotto bizz84@gmail.com 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | AppDelegate.h 3 | Copyright (c) 2013 Andrea Bizzotto bizz84@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | */ 11 | 12 | 13 | #import 14 | 15 | @interface AppDelegate : UIResponder 16 | 17 | @property (strong, nonatomic) UIWindow *window; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /* 2 | AppDelegate.m 3 | Copyright (c) 2013 Andrea Bizzotto bizz84@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | */ 11 | 12 | #import "AppDelegate.h" 13 | 14 | @implementation AppDelegate 15 | 16 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 17 | { 18 | // Override point for customization after application launch. 19 | return YES; 20 | } 21 | 22 | - (void)applicationWillResignActive:(UIApplication *)application 23 | { 24 | // 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. 25 | // 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. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application 29 | { 30 | // 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. 31 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 32 | } 33 | 34 | - (void)applicationWillEnterForeground:(UIApplication *)application 35 | { 36 | // 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. 37 | } 38 | 39 | - (void)applicationDidBecomeActive:(UIApplication *)application 40 | { 41 | // 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. 42 | } 43 | 44 | - (void)applicationWillTerminate:(UIApplication *)application 45 | { 46 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/AutoLayoutViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | AutoLayoutViewController.h 3 | Copyright (c) 2013 Andrea Bizzotto bizz84@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | */ 11 | 12 | #import 13 | 14 | @interface AutoLayoutViewController : UIViewController 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/AutoLayoutViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | AutoLayoutViewController.m 3 | Copyright (c) 2013 Andrea Bizzotto bizz84@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | */ 11 | 12 | 13 | #import "AutoLayoutViewController.h" 14 | #import "LayoutUtils.h" 15 | 16 | // This is a Masonry port of this tutorial: 17 | // http://www.apeth.com/iOSBook/ch20.html 18 | 19 | @interface AutoLayoutViewController () 20 | @property UIScrollView *scrollView; 21 | @end 22 | 23 | @implementation AutoLayoutViewController 24 | 25 | 26 | - (void)viewDidLoad 27 | { 28 | [super viewDidLoad]; 29 | 30 | if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) 31 | self.edgesForExtendedLayout = UIRectEdgeNone; 32 | 33 | // Create scroll view 34 | self.scrollView = [UIScrollView new]; 35 | self.scrollView.backgroundColor = [UIColor yellowColor]; 36 | [self.view addSubview:self.scrollView]; 37 | 38 | //[self createManually:self.scrollView]; 39 | [self createWithAutoLayout:self.scrollView numLabels:30]; 40 | } 41 | 42 | - (void)createWithAutoLayout:(UIScrollView *)scrollView numLabels:(int)numLabels { 43 | 44 | [scrollView makeConstraints:^(MASConstraintMaker *make) { 45 | make.edges.equalTo(self.view); 46 | }]; 47 | 48 | // Add header at beginning 49 | UILabel *header = [LayoutUtils fixedLabelWithText:@"UIScrollView with Auto-layout example"]; 50 | [scrollView addSubview:header]; 51 | 52 | // last one, pin to bottom and right, this dictates content size height 53 | [header makeConstraints:^(MASConstraintMaker *make) { 54 | make.top.equalTo(scrollView.top).offset(30); 55 | make.left.equalTo(scrollView.left).offset(10); 56 | //make.right.equalTo(self.mainScrollView.right).offset(-10);// Doesn't work 57 | make.width.equalTo(scrollView.width).offset(-20); 58 | make.height.equalTo(@50); 59 | }]; 60 | 61 | UILabel* previousLab = nil; 62 | for (int i = 0; i < numLabels; i++) { 63 | UILabel *lab = [LayoutUtils createLabelWithIndex:i target:self tapSelector:@selector(labTapped:)]; 64 | [scrollView addSubview:lab]; 65 | 66 | [lab makeConstraints:^(MASConstraintMaker *make) { 67 | make.left.equalTo(scrollView.left).offset(10); 68 | make.width.equalTo(scrollView.width).offset(-20); 69 | //make.right.equalTo(scrollView.right).offset(-10); // Doesn't work 70 | }]; 71 | 72 | if (!previousLab) { // first one, pin to top 73 | [lab makeConstraints:^(MASConstraintMaker *make) { 74 | make.top.equalTo(header.bottom).offset(10); 75 | }]; 76 | } else { // all others, pin to previous 77 | [lab makeConstraints:^(MASConstraintMaker *make) { 78 | make.top.equalTo(previousLab.bottom).offset(10); 79 | }]; 80 | } 81 | previousLab = lab; 82 | } 83 | 84 | // Add footer at end 85 | UILabel *footer = [LayoutUtils fixedLabelWithText:@"This is the end"]; 86 | [scrollView addSubview:footer]; 87 | 88 | // last one, pin to bottom and right, this dictates content size height 89 | [footer makeConstraints:^(MASConstraintMaker *make) { 90 | make.top.equalTo(previousLab.bottom).offset(10); 91 | make.left.equalTo(scrollView.left).offset(10); 92 | //make.right.equalTo(self.mainScrollView.right).offset(-10); 93 | make.width.equalTo(scrollView.width).offset(-20); 94 | make.height.equalTo(@50); 95 | make.bottom.equalTo(scrollView.bottom).offset(-10); 96 | }]; 97 | } 98 | 99 | 100 | - (void)viewDidAppear:(BOOL)animated { 101 | 102 | [super viewDidAppear:animated]; 103 | [LayoutUtils printClassAndFrameRecursive:self.view level:0]; 104 | DLog(@"scroll view content size: %@", NSStringFromCGSize(self.scrollView.contentSize)); 105 | } 106 | 107 | #pragma mark - event handlers 108 | 109 | - (void)labTapped:(UIGestureRecognizer *)sender { 110 | 111 | UILabel *label = (UILabel *)sender.view; 112 | label.text = @"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat."; 113 | } 114 | 115 | 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/Base.lproj/Main_iPad.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 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/Base.lproj/Main_iPhone.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 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/Images.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" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "ipad", 20 | "size" : "29x29", 21 | "scale" : "1x" 22 | }, 23 | { 24 | "idiom" : "ipad", 25 | "size" : "29x29", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "ipad", 30 | "size" : "40x40", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "40x40", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "76x76", 41 | "scale" : "1x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "76x76", 46 | "scale" : "2x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /ScrollViewAutoLayout/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "orientation" : "portrait", 20 | "idiom" : "ipad", 21 | "extent" : "full-screen", 22 | "minimum-system-version" : "7.0", 23 | "scale" : "1x" 24 | }, 25 | { 26 | "orientation" : "landscape", 27 | "idiom" : "ipad", 28 | "extent" : "full-screen", 29 | "minimum-system-version" : "7.0", 30 | "scale" : "1x" 31 | }, 32 | { 33 | "orientation" : "portrait", 34 | "idiom" : "ipad", 35 | "extent" : "full-screen", 36 | "minimum-system-version" : "7.0", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "orientation" : "landscape", 41 | "idiom" : "ipad", 42 | "extent" : "full-screen", 43 | "minimum-system-version" : "7.0", 44 | "scale" : "2x" 45 | } 46 | ], 47 | "info" : { 48 | "version" : 1, 49 | "author" : "xcode" 50 | } 51 | } -------------------------------------------------------------------------------- /ScrollViewAutoLayout/LayoutUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // LayoutUtils.h 3 | // ScrollViewAutoLayout 4 | // 5 | // Created by Andrea Bizzotto on 03/10/2013. 6 | // Copyright (c) 2013 Snupps. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LayoutUtils : NSObject 12 | 13 | + (UILabel *)createLabelWithIndex:(int)index target:(id)target tapSelector:(SEL)selector; 14 | + (UILabel *)fixedLabelWithText:(NSString *)text; 15 | + (void)printClassAndFrameRecursive:(UIView *)view level:(int)level; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/LayoutUtils.m: -------------------------------------------------------------------------------- 1 | // 2 | // LayoutUtils.m 3 | // ScrollViewAutoLayout 4 | // 5 | // Created by Andrea Bizzotto on 03/10/2013. 6 | // Copyright (c) 2013 Snupps. All rights reserved. 7 | // 8 | 9 | #import "LayoutUtils.h" 10 | 11 | @implementation LayoutUtils 12 | 13 | + (UILabel *)createLabelWithIndex:(int)index target:(id)target tapSelector:(SEL)selector { 14 | UILabel* lab = [UILabel new]; 15 | lab.translatesAutoresizingMaskIntoConstraints = NO; 16 | lab.text = [NSString stringWithFormat:@"This is label %i", index+1]; 17 | lab.backgroundColor = [UIColor redColor]; 18 | 19 | // Configure the label so that it increases it's size when tapped 20 | lab.numberOfLines = 0; 21 | lab.lineBreakMode = NSLineBreakByWordWrapping; 22 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:target action:selector]; 23 | [lab addGestureRecognizer:tap]; 24 | lab.userInteractionEnabled = YES; 25 | 26 | return lab; 27 | } 28 | 29 | + (UILabel *)fixedLabelWithText:(NSString *)text { 30 | 31 | UILabel *label = [UILabel new]; 32 | label.numberOfLines = 0; 33 | label.lineBreakMode = NSLineBreakByWordWrapping; 34 | label.translatesAutoresizingMaskIntoConstraints = NO; 35 | label.backgroundColor = [UIColor greenColor]; 36 | label.text = text; 37 | return label; 38 | } 39 | 40 | #pragma mark - utility methods 41 | 42 | + (void)printClassAndFrameRecursive:(UIView *)view level:(int)level { 43 | 44 | NSMutableString *prefix = [NSMutableString new]; 45 | for (int i = 0; i < level; i++) 46 | [prefix appendString:@"-"]; 47 | 48 | NSLog(@"%@> Class: %@, frame: %@", prefix, [[view class] description], NSStringFromCGRect(view.frame)); 49 | for (UIView *sv in view.subviews) { 50 | [self printClassAndFrameRecursive:sv level:level + 1]; 51 | } 52 | } 53 | @end 54 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/MVScrollViewAutoLayout-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.musevisions.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main_iPhone 29 | UIMainStoryboardFile~ipad 30 | Main_iPad 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/MVScrollViewAutoLayout-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | 18 | #define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) 19 | 20 | #define MAS_SHORTHAND 21 | 22 | #import "Masonry.h" -------------------------------------------------------------------------------- /ScrollViewAutoLayout/SpringsAndStroutsViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | SpringsAndStroutsViewController.h 3 | Copyright (c) 2013 Andrea Bizzotto bizz84@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | */ 11 | 12 | #import 13 | 14 | 15 | @interface SpringsAndStroutsViewController : UIViewController 16 | @end -------------------------------------------------------------------------------- /ScrollViewAutoLayout/SpringsAndStroutsViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | SpringsAndStroutsViewController.h 3 | Copyright (c) 2013 Andrea Bizzotto bizz84@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | */ 11 | 12 | 13 | #import "SpringsAndStroutsViewController.h" 14 | #import "LayoutUtils.h" 15 | 16 | static const int kNumLabels = 30; 17 | 18 | @interface SpringsAndStroutsViewController () 19 | @property UIScrollView *scrollView; 20 | @property int numLabels; 21 | @end 22 | 23 | @implementation SpringsAndStroutsViewController 24 | 25 | - (void)viewDidLoad 26 | { 27 | [super viewDidLoad]; 28 | 29 | if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) 30 | self.edgesForExtendedLayout = UIRectEdgeNone; 31 | 32 | // Create scroll view 33 | self.scrollView = [UIScrollView new]; 34 | self.scrollView.backgroundColor = [UIColor yellowColor]; 35 | // Set autoresizing mask to account for screen rotation 36 | self.scrollView.autoresizingMask =(UIViewAutoresizingFlexibleWidth | 37 | UIViewAutoresizingFlexibleHeight); 38 | [self.view addSubview:self.scrollView]; 39 | 40 | 41 | [self createWithSpringsAndStrouts:self.scrollView numLabels:kNumLabels]; 42 | } 43 | 44 | - (void)viewDidAppear:(BOOL)animated { 45 | 46 | [super viewDidAppear:animated]; 47 | [LayoutUtils printClassAndFrameRecursive:self.view level:0]; 48 | DLog(@"scroll view content size: %@", NSStringFromCGSize(self.scrollView.contentSize)); 49 | } 50 | 51 | - (void)createWithSpringsAndStrouts:(UIScrollView *)scrollView numLabels:(int)numLabels { 52 | 53 | for (int i = 0; i < numLabels; i++) { 54 | UILabel* lab = [LayoutUtils createLabelWithIndex:i target:self tapSelector:@selector(labTapped:)]; 55 | [scrollView addSubview:lab]; 56 | } 57 | [self updateLayout:self.scrollView numLabels:numLabels]; 58 | } 59 | 60 | - (void)adjustLabel:(UILabel *)label originY:(float)originY { 61 | // TODO: Fix this to work in multi-line mode 62 | [label sizeToFit]; 63 | CGRect f = label.frame; 64 | f.origin = CGPointMake(10,originY); 65 | label.frame = f; 66 | } 67 | 68 | - (void)labTapped:(UIGestureRecognizer *)sender { 69 | 70 | UILabel *label = (UILabel *)sender.view; 71 | label.text = @"Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat."; 72 | // content size needs to be recalculated each time 73 | [self updateLayout:self.scrollView numLabels:kNumLabels]; 74 | } 75 | 76 | - (void)updateLayout:(UIScrollView *)scrollView numLabels:(int)numLabels { 77 | 78 | CGFloat y = 10; 79 | for (int i = 0; i < numLabels; i++) { 80 | UILabel* lab = [self.scrollView.subviews objectAtIndex:i]; 81 | [self adjustLabel:lab originY:y]; 82 | y += lab.bounds.size.height + 10; 83 | } 84 | CGSize sz = scrollView.bounds.size; 85 | sz.height = y; 86 | scrollView.contentSize = sz; 87 | scrollView.frame = self.view.frame; 88 | } 89 | 90 | @end -------------------------------------------------------------------------------- /ScrollViewAutoLayout/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /ScrollViewAutoLayout/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ScrollViewAutoLayout 4 | // 5 | // Created by Andrea Bizzotto on 02/10/2013. 6 | // Copyright (c) 2013 Snupps. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /auto-layout-scroll-view-preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bizz84/MVScrollViewAutoLayout/2074171110c8bfc8b710c67c9b08b56bdabcf6d6/auto-layout-scroll-view-preview.png --------------------------------------------------------------------------------