From ebc2abd6713e1d46ee2829b1a2e450fadc0a7833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dudek?= Date: Thu, 14 Jan 2016 15:45:09 +0100 Subject: [PATCH] Fixed issues with layout not considering collection view content insets --- .../project.pbxproj | 87 +++++++++++-------- CarouselCollectionViewLayout/AppDelegate.m | 6 +- .../CarouselCollectionViewLayout-Info.plist | 82 ++++++++--------- ...ctionViewLayoutHorizontalPropertiesCache.h | 13 +++ ...ctionViewLayoutHorizontalPropertiesCache.m | 64 ++++++++++++++ .../Lib/PBDCarouselCollectionViewLayout.h | 21 +++++ .../Lib/PBDCarouselCollectionViewLayout.m | 28 +++--- ...rouselCollectionViewLayoutTests-Info.plist | 22 ----- ...rouselCollectionViewLayoutTests-Info.plist | 22 +++++ ...rouselCollectionViewLayoutTests-Prefix.pch | 18 ++++ .../en.lproj/InfoPlist.strings | 0 11 files changed, 245 insertions(+), 118 deletions(-) create mode 100644 CarouselCollectionViewLayout/Classes/Lib/Helpers/PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.h create mode 100644 CarouselCollectionViewLayout/Classes/Lib/Helpers/PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m delete mode 100644 CarouselCollectionViewLayoutTests/CarouselCollectionViewLayoutTests-Info.plist create mode 100644 CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Info.plist create mode 100644 CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Prefix.pch rename CarouselCollectionViewLayoutTests/{ => Resources}/en.lproj/InfoPlist.strings (100%) diff --git a/CarouselCollectionViewLayout.xcodeproj/project.pbxproj b/CarouselCollectionViewLayout.xcodeproj/project.pbxproj index 471ee44..03f4140 100644 --- a/CarouselCollectionViewLayout.xcodeproj/project.pbxproj +++ b/CarouselCollectionViewLayout.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 47; objects = { /* Begin PBXBuildFile section */ @@ -17,8 +17,8 @@ 43078F69197BD9FD0025ECBF /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43078F68197BD9FD0025ECBF /* XCTest.framework */; }; 43078F6A197BD9FD0025ECBF /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43078F4F197BD9FD0025ECBF /* Foundation.framework */; }; 43078F6B197BD9FD0025ECBF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43078F53197BD9FD0025ECBF /* UIKit.framework */; }; - 43078F73197BD9FD0025ECBF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 43078F71197BD9FD0025ECBF /* InfoPlist.strings */; }; 43078F75197BD9FD0025ECBF /* CarouselLayoutTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 43078F74197BD9FD0025ECBF /* CarouselLayoutTests.m */; }; + B27A913BFA596301C18A9698 /* PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m in Sources */ = {isa = PBXBuildFile; fileRef = B27A966E3FC40E0996945370 /* PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m */; }; B27A94D3F3143E09C71A455F /* PBDCarouselCollectionViewLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B27A9F7C36FCCD1A28D832CE /* PBDCarouselCollectionViewLayout.m */; }; B27A96663940BFABA727FAC0 /* CarouselCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B27A954C849FCCE3E366BB70 /* CarouselCollectionViewController.m */; }; /* End PBXBuildFile section */ @@ -34,7 +34,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 43078F4C197BD9FD0025ECBF /* CarouselCollectionViewLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CarouselCollectionViewLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 43078F4C197BD9FD0025ECBF /* PBDCarouselCollectionViewLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PBDCarouselCollectionViewLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43078F4F197BD9FD0025ECBF /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 43078F51197BD9FD0025ECBF /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 43078F53197BD9FD0025ECBF /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; @@ -45,14 +45,16 @@ 43078F5E197BD9FD0025ECBF /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 43078F5F197BD9FD0025ECBF /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 43078F61197BD9FD0025ECBF /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; - 43078F67197BD9FD0025ECBF /* CarouselCollectionViewLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CarouselCollectionViewLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 43078F67197BD9FD0025ECBF /* PBDCarouselCollectionViewLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PBDCarouselCollectionViewLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43078F68197BD9FD0025ECBF /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; - 43078F70197BD9FD0025ECBF /* CarouselCollectionViewLayoutTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.info; path = "CarouselCollectionViewLayoutTests-Info.plist"; sourceTree = ""; }; - 43078F72197BD9FD0025ECBF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 43078F74197BD9FD0025ECBF /* CarouselLayoutTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CarouselLayoutTests.m; sourceTree = ""; }; + 439841EE1C47E28600719676 /* CarouselCollectionViewLayoutTests-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CarouselCollectionViewLayoutTests-Prefix.pch"; sourceTree = ""; }; + 439841EF1C47E28600719676 /* CarouselCollectionViewLayoutTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "CarouselCollectionViewLayoutTests-Info.plist"; sourceTree = ""; }; B27A900D6191713D16CE53F3 /* CarouselCollectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CarouselCollectionViewController.h; sourceTree = ""; }; + B27A92408CE32697829986F2 /* PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.h; sourceTree = ""; }; B27A92B41B76EEAE062EF3A4 /* PBDCarouselCollectionViewLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBDCarouselCollectionViewLayout.h; sourceTree = ""; }; B27A954C849FCCE3E366BB70 /* CarouselCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CarouselCollectionViewController.m; sourceTree = ""; }; + B27A966E3FC40E0996945370 /* PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m; sourceTree = ""; }; B27A9F7C36FCCD1A28D832CE /* PBDCarouselCollectionViewLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBDCarouselCollectionViewLayout.m; sourceTree = ""; }; /* End PBXFileReference section */ @@ -93,8 +95,8 @@ 43078F4D197BD9FD0025ECBF /* Products */ = { isa = PBXGroup; children = ( - 43078F4C197BD9FD0025ECBF /* CarouselCollectionViewLayout.app */, - 43078F67197BD9FD0025ECBF /* CarouselCollectionViewLayoutTests.xctest */, + 43078F4C197BD9FD0025ECBF /* PBDCarouselCollectionViewLayout.app */, + 43078F67197BD9FD0025ECBF /* PBDCarouselCollectionViewLayoutTests.xctest */, ); name = Products; sourceTree = ""; @@ -145,12 +147,20 @@ 43078F6F197BD9FD0025ECBF /* Supporting Files */ = { isa = PBXGroup; children = ( - 43078F70197BD9FD0025ECBF /* CarouselCollectionViewLayoutTests-Info.plist */, - 43078F71197BD9FD0025ECBF /* InfoPlist.strings */, + 439841ED1C47E25C00719676 /* Resources */, ); name = "Supporting Files"; sourceTree = ""; }; + 439841ED1C47E25C00719676 /* Resources */ = { + isa = PBXGroup; + children = ( + 439841EE1C47E28600719676 /* CarouselCollectionViewLayoutTests-Prefix.pch */, + 439841EF1C47E28600719676 /* CarouselCollectionViewLayoutTests-Info.plist */, + ); + path = Resources; + sourceTree = ""; + }; B27A968CAA7E3C5E790F7515 /* Demo */ = { isa = PBXGroup; children = ( @@ -169,11 +179,21 @@ path = Classes; sourceTree = ""; }; + B27A981EA672C5FE98221A8F /* Helpers */ = { + isa = PBXGroup; + children = ( + B27A966E3FC40E0996945370 /* PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m */, + B27A92408CE32697829986F2 /* PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.h */, + ); + path = Helpers; + sourceTree = ""; + }; B27A9E6A011735C5D4F66808 /* Lib */ = { isa = PBXGroup; children = ( B27A92B41B76EEAE062EF3A4 /* PBDCarouselCollectionViewLayout.h */, B27A9F7C36FCCD1A28D832CE /* PBDCarouselCollectionViewLayout.m */, + B27A981EA672C5FE98221A8F /* Helpers */, ); path = Lib; sourceTree = ""; @@ -195,7 +215,7 @@ ); name = CarouselCollectionViewLayout; productName = CarouselLayout; - productReference = 43078F4C197BD9FD0025ECBF /* CarouselCollectionViewLayout.app */; + productReference = 43078F4C197BD9FD0025ECBF /* PBDCarouselCollectionViewLayout.app */; productType = "com.apple.product-type.application"; }; 43078F66197BD9FD0025ECBF /* CarouselCollectionViewLayoutTests */ = { @@ -213,7 +233,7 @@ ); name = CarouselCollectionViewLayoutTests; productName = CarouselLayoutTests; - productReference = 43078F67197BD9FD0025ECBF /* CarouselCollectionViewLayoutTests.xctest */; + productReference = 43078F67197BD9FD0025ECBF /* PBDCarouselCollectionViewLayoutTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -222,7 +242,7 @@ 43078F44197BD9FD0025ECBF /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0510; + LastUpgradeCheck = 0720; ORGANIZATIONNAME = dudek; TargetAttributes = { 43078F66197BD9FD0025ECBF = { @@ -231,7 +251,7 @@ }; }; buildConfigurationList = 43078F47197BD9FD0025ECBF /* Build configuration list for PBXProject "CarouselCollectionViewLayout" */; - compatibilityVersion = "Xcode 3.2"; + compatibilityVersion = "Xcode 6.3"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( @@ -262,7 +282,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 43078F73197BD9FD0025ECBF /* InfoPlist.strings in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -277,6 +296,7 @@ 43078F5C197BD9FD0025ECBF /* main.m in Sources */, B27A94D3F3143E09C71A455F /* PBDCarouselCollectionViewLayout.m in Sources */, B27A96663940BFABA727FAC0 /* CarouselCollectionViewController.m in Sources */, + B27A913BFA596301C18A9698 /* PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -307,14 +327,6 @@ name = InfoPlist.strings; sourceTree = ""; }; - 43078F71197BD9FD0025ECBF /* InfoPlist.strings */ = { - isa = PBXVariantGroup; - children = ( - 43078F72197BD9FD0025ECBF /* en */, - ); - name = InfoPlist.strings; - sourceTree = ""; - }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -336,6 +348,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -350,7 +363,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -383,7 +396,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -398,7 +411,8 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "CarouselCollectionViewLayout/CarouselCollectionViewLayout-Prefix.pch"; INFOPLIST_FILE = "CarouselCollectionViewLayout/CarouselCollectionViewLayout-Info.plist"; - PRODUCT_NAME = CarouselCollectionViewLayout; + PRODUCT_BUNDLE_IDENTIFIER = "mobi.dudek.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = PBDCarouselCollectionViewLayout; TARGETED_DEVICE_FAMILY = "1,2"; WRAPPER_EXTENSION = app; }; @@ -412,7 +426,8 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "CarouselCollectionViewLayout/CarouselCollectionViewLayout-Prefix.pch"; INFOPLIST_FILE = "CarouselCollectionViewLayout/CarouselCollectionViewLayout-Info.plist"; - PRODUCT_NAME = CarouselCollectionViewLayout; + PRODUCT_BUNDLE_IDENTIFIER = "mobi.dudek.${PRODUCT_NAME:rfc1034identifier}"; + PRODUCT_NAME = PBDCarouselCollectionViewLayout; TARGETED_DEVICE_FAMILY = "1,2"; WRAPPER_EXTENSION = app; }; @@ -421,20 +436,19 @@ 43078F7C197BD9FD0025ECBF /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/CarouselLayout.app/CarouselLayout"; + BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/PBDCarouselCollectionViewLayout.app/PBDCarouselCollectionViewLayout"; FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", "$(DEVELOPER_FRAMEWORKS_DIR)", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "CarouselLayout/CarouselLayout-Prefix.pch"; + GCC_PREFIX_HEADER = "CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Prefix.pch"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = "CarouselLayoutTests/CarouselCollectionViewLayoutTests-Info.plist"; - PRODUCT_NAME = CarouselCollectionViewLayoutTests; + INFOPLIST_FILE = "CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Info.plist"; + PRODUCT_NAME = PBDCarouselCollectionViewLayoutTests; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; }; @@ -443,16 +457,15 @@ 43078F7D197BD9FD0025ECBF /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/CarouselLayout.app/CarouselLayout"; + BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/PBDCarouselCollectionViewLayout.app/PBDCarouselCollectionViewLayout"; FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", "$(DEVELOPER_FRAMEWORKS_DIR)", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "CarouselLayout/CarouselLayout-Prefix.pch"; - INFOPLIST_FILE = "CarouselLayoutTests/CarouselCollectionViewLayoutTests-Info.plist"; - PRODUCT_NAME = CarouselCollectionViewLayoutTests; + GCC_PREFIX_HEADER = "CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Prefix.pch"; + INFOPLIST_FILE = "CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Info.plist"; + PRODUCT_NAME = PBDCarouselCollectionViewLayoutTests; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; }; diff --git a/CarouselCollectionViewLayout/AppDelegate.m b/CarouselCollectionViewLayout/AppDelegate.m index 8c1f67f..c3976a8 100644 --- a/CarouselCollectionViewLayout/AppDelegate.m +++ b/CarouselCollectionViewLayout/AppDelegate.m @@ -14,7 +14,11 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - self.window.rootViewController = [[CarouselCollectionViewController alloc] init]; + CarouselCollectionViewController *carouselCollectionViewController = [[CarouselCollectionViewController alloc] init]; + UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:carouselCollectionViewController]; + navigationController.toolbarHidden = NO; + navigationController.navigationBarHidden = YES; + self.window.rootViewController = navigationController; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; diff --git a/CarouselCollectionViewLayout/CarouselCollectionViewLayout-Info.plist b/CarouselCollectionViewLayout/CarouselCollectionViewLayout-Info.plist index 89bf3d6..6a012bd 100644 --- a/CarouselCollectionViewLayout/CarouselCollectionViewLayout-Info.plist +++ b/CarouselCollectionViewLayout/CarouselCollectionViewLayout-Info.plist @@ -1,45 +1,45 @@ - - CFBundleDevelopmentRegion - en - CFBundleDisplayName - ${PRODUCT_NAME} - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - mobi.dudek.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1.0 - LSRequiresIPhoneOS - - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + diff --git a/CarouselCollectionViewLayout/Classes/Lib/Helpers/PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.h b/CarouselCollectionViewLayout/Classes/Lib/Helpers/PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.h new file mode 100644 index 0000000..656f9e9 --- /dev/null +++ b/CarouselCollectionViewLayout/Classes/Lib/Helpers/PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.h @@ -0,0 +1,13 @@ +/* +* Copyright (c) 2016 Pawel Dudek. All rights reserved. +*/ +#import +#import "PBDCarouselCollectionViewLayout.h" + +@interface PBDCarouselCollectionViewLayoutHorizontalPropertiesCache : NSObject + +@property(nonatomic, weak, readonly) PBDCarouselCollectionViewLayout *layout; + +- (instancetype)initWithLayout:(PBDCarouselCollectionViewLayout *)layout; + +@end diff --git a/CarouselCollectionViewLayout/Classes/Lib/Helpers/PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m b/CarouselCollectionViewLayout/Classes/Lib/Helpers/PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m new file mode 100644 index 0000000..2b90286 --- /dev/null +++ b/CarouselCollectionViewLayout/Classes/Lib/Helpers/PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.m @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016 Pawel Dudek. All rights reserved. + */ +#import "PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.h" + + +@interface PBDCarouselCollectionViewLayoutHorizontalPropertiesCache () +/* + * Content rect, considering content inset of collection view. + */ +@property(nonatomic, readwrite) CGRect contentRect; + +/* + * Point on x axis that defines where actual content starts, considering size and content inset of collection view + */ +@property(nonatomic, readwrite) CGFloat contentStart; + +@property(nonatomic) CGFloat cellYPosition; + +@end + +@implementation PBDCarouselCollectionViewLayoutHorizontalPropertiesCache + +- (instancetype)initWithLayout:(PBDCarouselCollectionViewLayout *)layout { + self = [super init]; + if (self) { + _layout = layout; + + [self calculateLayoutProperties]; + } + + return self; +} + +#pragma mark - Calculating Layout Properties + +- (void)calculateLayoutProperties { + UICollectionView *collectionView = self.layout.collectionView; + + CGSize collectionViewSize = collectionView.bounds.size; + CGFloat rightLeftMargin = (collectionViewSize.width - self.layout.itemSize.width) / 2; + CGFloat topBottomMargin = (collectionViewSize.height - self.layout.itemSize.height) / 2; + + NSInteger numberOfItems = [collectionView numberOfItemsInSection:0]; + + // Content rect will be the actual content minus collection view insets + CGFloat contentWidth = numberOfItems * self.layout.itemSize.width + (numberOfItems - 1) * self.layout.interItemSpace + 2 * rightLeftMargin; + CGFloat contentHeight = self.layout.itemSize.height + 2 * topBottomMargin; + + CGRect contentRect = CGRectMake(0, 0, contentWidth, contentHeight); + self.contentRect = UIEdgeInsetsInsetRect(contentRect, collectionView.contentInset); + + self.contentStart = rightLeftMargin; + self.cellYPosition = CGRectGetMidY(self.contentRect) - collectionView.contentInset.top; +} + +#pragma mark - + +- (CGPoint)centerForItemAtIndexPath:(NSIndexPath *)indexPath { + CGFloat x = self.contentStart + indexPath.row * (self.layout.itemSize.width + self.layout.interItemSpace) + self.layout.itemSize.width / 2; + return CGPointMake(x, self.cellYPosition); +} + +@end diff --git a/CarouselCollectionViewLayout/Classes/Lib/PBDCarouselCollectionViewLayout.h b/CarouselCollectionViewLayout/Classes/Lib/PBDCarouselCollectionViewLayout.h index ab0b3dd..9e431a3 100644 --- a/CarouselCollectionViewLayout/Classes/Lib/PBDCarouselCollectionViewLayout.h +++ b/CarouselCollectionViewLayout/Classes/Lib/PBDCarouselCollectionViewLayout.h @@ -5,9 +5,30 @@ #import +@protocol PBDCarouselCollectionViewLayoutPropertiesCache + +/* + * Content rect, considering content inset of collection view. + */ +@property(nonatomic, readonly) CGRect contentRect; + +/* + * Point on x axis that defines where actual content starts, considering size and content inset of collection view + */ +@property(nonatomic, readonly) CGFloat contentStart; + +#pragma mark - Obtaining Item Position + +- (CGPoint)centerForItemAtIndexPath:(NSIndexPath *)indexPath; + +@end + @interface PBDCarouselCollectionViewLayout : UICollectionViewLayout @property(nonatomic) CGSize itemSize; + @property(nonatomic) CGFloat interItemSpace; +@property(nonatomic) CGSize headerFooterSize; + @end diff --git a/CarouselCollectionViewLayout/Classes/Lib/PBDCarouselCollectionViewLayout.m b/CarouselCollectionViewLayout/Classes/Lib/PBDCarouselCollectionViewLayout.m index 271eb21..0503545 100644 --- a/CarouselCollectionViewLayout/Classes/Lib/PBDCarouselCollectionViewLayout.m +++ b/CarouselCollectionViewLayout/Classes/Lib/PBDCarouselCollectionViewLayout.m @@ -4,11 +4,14 @@ #import "PBDCarouselCollectionViewLayout.h" +#import "PBDCarouselCollectionViewLayoutHorizontalPropertiesCache.h" @interface PBDCarouselCollectionViewLayout () -@property(nonatomic) CGFloat rightLeftMargin; -@property(nonatomic) CGFloat topBottomMargin; + @property(nonatomic, strong) NSIndexPath *indexPathForCenteredItem; + +@property(nonatomic, strong) id propertiesCache; + @end @implementation PBDCarouselCollectionViewLayout @@ -18,18 +21,11 @@ @implementation PBDCarouselCollectionViewLayout - (void)prepareLayout { [super prepareLayout]; - CGSize collectionViewSize = self.collectionView.bounds.size; - self.rightLeftMargin = (collectionViewSize.width - self.itemSize.width) / 2; - self.topBottomMargin = (collectionViewSize.height - self.itemSize.height) / 2; + self.propertiesCache = [[PBDCarouselCollectionViewLayoutHorizontalPropertiesCache alloc] initWithLayout:self]; } - (CGSize)collectionViewContentSize { - NSInteger numberOfItems = [self.collectionView numberOfItemsInSection:0]; - - CGFloat contentWidth = numberOfItems * self.itemSize.width + (numberOfItems - 1) * self.interItemSpace + 2 * self.rightLeftMargin; - CGFloat contentHeight = self.itemSize.height + 2 * self.topBottomMargin; - - return CGSizeMake(contentWidth, contentHeight); + return self.propertiesCache.contentRect.size; } #pragma mark - Attributes @@ -37,8 +33,8 @@ - (CGSize)collectionViewContentSize { - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { CGFloat combinedItemWidth = self.itemSize.width + self.interItemSpace; - CGFloat minimalXPosition = CGRectGetMinX(rect) - self.rightLeftMargin; - CGFloat maximalXPosition = CGRectGetMaxX(rect) - self.rightLeftMargin; + CGFloat minimalXPosition = CGRectGetMinX(rect) - self.propertiesCache.contentStart; + CGFloat maximalXPosition = CGRectGetMaxX(rect) - self.propertiesCache.contentStart; CGFloat firstVisibleItem = floorf(minimalXPosition / combinedItemWidth); CGFloat lastVisibleItem = ceilf(maximalXPosition / combinedItemWidth); @@ -68,9 +64,7 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSInde bounds.size = self.itemSize; attributes.bounds = bounds; - CGFloat x = self.rightLeftMargin + indexPath.row * (self.itemSize.width + self.interItemSpace) + self.itemSize.width / 2; - CGFloat y = self.collectionView.frame.size.height / 2; - attributes.center = CGPointMake(x, y); + attributes.center = [self.propertiesCache centerForItemAtIndexPath:indexPath]; return attributes; } @@ -142,7 +136,7 @@ - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { return !CGSizeEqualToSize(self.collectionView.bounds.size, newBounds.size); } -#pragma mark - Overriden Setters +#pragma mark - Overridden Setters - (void)setItemSize:(CGSize)itemSize { if (!CGSizeEqualToSize(_itemSize, itemSize)) { diff --git a/CarouselCollectionViewLayoutTests/CarouselCollectionViewLayoutTests-Info.plist b/CarouselCollectionViewLayoutTests/CarouselCollectionViewLayoutTests-Info.plist deleted file mode 100644 index 8e57780..0000000 --- a/CarouselCollectionViewLayoutTests/CarouselCollectionViewLayoutTests-Info.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - mobi.dudek.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Info.plist b/CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Info.plist new file mode 100644 index 0000000..e3c5750 --- /dev/null +++ b/CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + mobi.dudek.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Prefix.pch b/CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Prefix.pch new file mode 100644 index 0000000..43f34b8 --- /dev/null +++ b/CarouselCollectionViewLayoutTests/Resources/CarouselCollectionViewLayoutTests-Prefix.pch @@ -0,0 +1,18 @@ +// +// Prefix header +// +// The contents of this file are implicitly included at the beginning of every source file. +// + +#import + +#ifndef __IPHONE_3_0 +#warning "This project uses features only available in iOS SDK 3.0 and later." +#endif + +#ifdef __OBJC__ + +#import +#import + +#endif diff --git a/CarouselCollectionViewLayoutTests/en.lproj/InfoPlist.strings b/CarouselCollectionViewLayoutTests/Resources/en.lproj/InfoPlist.strings similarity index 100% rename from CarouselCollectionViewLayoutTests/en.lproj/InfoPlist.strings rename to CarouselCollectionViewLayoutTests/Resources/en.lproj/InfoPlist.strings