Skip to content

Commit

Permalink
Migrate to Swift 4.2 and add settings for iPhone X, Xs, XR and Xs Max…
Browse files Browse the repository at this point in the history
… landscape support
  • Loading branch information
Terence Chen committed Oct 17, 2018
1 parent 6203e7e commit 8d0965a
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 243 deletions.
55 changes: 34 additions & 21 deletions Sources/ASHorizontalScrollView.swift
@@ -1,24 +1,25 @@
/* ---------------------------------------------------------
* ASHorizontalScrollView.swift
* The MIT License (MIT)
* Copyright (C) 2014-2017 WEIWEI CHEN
* ---------------------------------------------------------
* History
* Created by WEIWEI CHEN on 14-6-8.
* Edit by WEIWEI CHEN 14-9-21: fix problems to work on xcode 6.0.1
* Edit by WEIWEI CHEN 15-12-09: change to adapt Swift 2.1, add comments on functions, remove scale when calculating margin, it seems that the behaviour in iOS 9 change the way of align views
* Edit by WEIWEI CHEN 16-05-17: change C style code to swift 3 format, fix removeItemAtIndex last index crash bug
* Edit by WEIWEI CHEN 16-09-15: Change to adapt Swift 3 with Xcode 8, add support to nib, just change the class on nib file to ASHorizontalScrollView
* Edit by WEIWEI CHEN 16-12-02: When current item scroll to more than specified width, auto scroll to next item (mimic App Store behaviour which is about 1/3); add support to all apple screen sizes, now you can specified different mini margin, mini appear width and left margin for all sorts of screen sizes.
* Edit by WEIWEI CHEN 17-01-24: Introduce new properties to allow set number of items per screen for multiple screen sizes instead of setting minimum margins, as well as new properties to center subviews when items are not wide enough to use whole screen width
* Edit by WEIWEI CHEN 17-03-03: check items size before removing all items
*
* 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:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* 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.
* -------------------------------------------------------*/
* ASHorizontalScrollView.swift
* The MIT License (MIT)
* Copyright (C) 2014-Current WEIWEI CHEN
* ---------------------------------------------------------
* History
* Created by WEIWEI CHEN on 14-6-8.
* Edit by WEIWEI CHEN 14-9-21: fix problems to work on xcode 6.0.1
* Edit by WEIWEI CHEN 15-12-09: change to adapt Swift 2.1, add comments on functions, remove scale when calculating margin, it seems that the behaviour in iOS 9 change the way of align views
* Edit by WEIWEI CHEN 16-05-17: change C style code to swift 3 format, fix removeItemAtIndex last index crash bug
* Edit by WEIWEI CHEN 16-09-15: Change to adapt Swift 3 with Xcode 8, add support to nib, just change the class on nib file to ASHorizontalScrollView
* Edit by WEIWEI CHEN 16-12-02: When current item scroll to more than specified width, auto scroll to next item (mimic App Store behaviour which is about 1/3); add support to all apple screen sizes, now you can specified different mini margin, mini appear width and left margin for all sorts of screen sizes.
* Edit by WEIWEI CHEN 17-01-24: Introduce new properties to allow set number of items per screen for multiple screen sizes instead of setting minimum margins, as well as new properties to center subviews when items are not wide enough to use whole screen width
* Edit by WEIWEI CHEN 17-03-03: check items size before removing all items
* Edit by WEIWEI CHEN 18-10-17: migrate to Swift 4.2 and add settings for iPhone X, Xs, XR and Xs Max landscape support, thanks to Anton Dryakhlykh help on the migration.
*
* 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:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* 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.
* -------------------------------------------------------*/

import UIKit

Expand Down Expand Up @@ -81,7 +82,7 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate {
}
}
}


/// whether to arrange items by frame or by number of items, if set by frame, all margin would be calculated by frame size, otherwise, calculated by number of items per screen
/// - check `numberOfItemsPerScreen` for arranged by number type
Expand Down Expand Up @@ -143,6 +144,14 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate {
if let setting = marginSettings_736 {
return setting
}
case 812:
if let setting = marginSettings_812 {
return setting
}
case 896:
if let setting = marginSettings_896 {
return setting
}
case 1366:
if let setting = marginSettings_1366 {
return setting
Expand Down Expand Up @@ -174,6 +183,10 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate {
public var marginSettings_667:MarginSettings?
/// for iPhone 6 plus and 6s plus in landscape
public var marginSettings_736:MarginSettings?
/// for iPhone X and Xs in landscape
public var marginSettings_812:MarginSettings?
/// for iPhone Xs Max and XR in landscape
public var marginSettings_896:MarginSettings?
/// for ipad and ipad pro 9.7 in landscape and ipad pro 12.9 portrait
public var marginSettings_1024:MarginSettings?
/// for ipad pro 12.9 in landscape
Expand Down
Expand Up @@ -11,30 +11,16 @@
7465DEDD19453DB100AA9A5D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7465DEDC19453DB100AA9A5D /* ViewController.swift */; };
7465DEE019453DB100AA9A5D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7465DEDE19453DB100AA9A5D /* Main.storyboard */; };
7465DEE219453DB100AA9A5D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7465DEE119453DB100AA9A5D /* Images.xcassets */; };
7465DEEE19453DB100AA9A5D /* sampleScorllViewInSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7465DEED19453DB100AA9A5D /* sampleScorllViewInSwiftTests.swift */; };
7465DEF819453E5800AA9A5D /* ASHorizontalScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7465DEF719453E5800AA9A5D /* ASHorizontalScrollView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
7465DEE819453DB100AA9A5D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 7465DECD19453DB100AA9A5D /* Project object */;
proxyType = 1;
remoteGlobalIDString = 7465DED419453DB100AA9A5D;
remoteInfo = sampleScorllViewInSwift;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
7465DED519453DB100AA9A5D /* sampleScorllViewInSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = sampleScorllViewInSwift.app; sourceTree = BUILT_PRODUCTS_DIR; };
7465DED919453DB100AA9A5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7465DEDA19453DB100AA9A5D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7465DEDC19453DB100AA9A5D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
7465DEDF19453DB100AA9A5D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
7465DEE119453DB100AA9A5D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
7465DEE719453DB100AA9A5D /* sampleScorllViewInSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = sampleScorllViewInSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7465DEEC19453DB100AA9A5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7465DEED19453DB100AA9A5D /* sampleScorllViewInSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = sampleScorllViewInSwiftTests.swift; sourceTree = "<group>"; };
7465DEF719453E5800AA9A5D /* ASHorizontalScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASHorizontalScrollView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -46,21 +32,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
7465DEE419453DB100AA9A5D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
7465DECC19453DB100AA9A5D = {
isa = PBXGroup;
children = (
7465DED719453DB100AA9A5D /* sampleScorllViewInSwift */,
7465DEEA19453DB100AA9A5D /* sampleScorllViewInSwiftTests */,
7465DED619453DB100AA9A5D /* Products */,
);
sourceTree = "<group>";
Expand All @@ -69,7 +47,6 @@
isa = PBXGroup;
children = (
7465DED519453DB100AA9A5D /* sampleScorllViewInSwift.app */,
7465DEE719453DB100AA9A5D /* sampleScorllViewInSwiftTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -95,23 +72,6 @@
name = "Supporting Files";
sourceTree = "<group>";
};
7465DEEA19453DB100AA9A5D /* sampleScorllViewInSwiftTests */ = {
isa = PBXGroup;
children = (
7465DEED19453DB100AA9A5D /* sampleScorllViewInSwiftTests.swift */,
7465DEEB19453DB100AA9A5D /* Supporting Files */,
);
path = sampleScorllViewInSwiftTests;
sourceTree = "<group>";
};
7465DEEB19453DB100AA9A5D /* Supporting Files */ = {
isa = PBXGroup;
children = (
7465DEEC19453DB100AA9A5D /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -132,24 +92,6 @@
productReference = 7465DED519453DB100AA9A5D /* sampleScorllViewInSwift.app */;
productType = "com.apple.product-type.application";
};
7465DEE619453DB100AA9A5D /* sampleScorllViewInSwiftTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 7465DEF419453DB100AA9A5D /* Build configuration list for PBXNativeTarget "sampleScorllViewInSwiftTests" */;
buildPhases = (
7465DEE319453DB100AA9A5D /* Sources */,
7465DEE419453DB100AA9A5D /* Frameworks */,
7465DEE519453DB100AA9A5D /* Resources */,
);
buildRules = (
);
dependencies = (
7465DEE919453DB100AA9A5D /* PBXTargetDependency */,
);
name = sampleScorllViewInSwiftTests;
productName = sampleScorllViewInSwiftTests;
productReference = 7465DEE719453DB100AA9A5D /* sampleScorllViewInSwiftTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
Expand All @@ -158,18 +100,13 @@
attributes = {
LastSwiftMigration = 0710;
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = Zuse;
TargetAttributes = {
7465DED419453DB100AA9A5D = {
CreatedOnToolsVersion = 6.0;
LastSwiftMigration = 0810;
};
7465DEE619453DB100AA9A5D = {
CreatedOnToolsVersion = 6.0;
LastSwiftMigration = 0810;
TestTargetID = 7465DED419453DB100AA9A5D;
};
};
};
buildConfigurationList = 7465DED019453DB100AA9A5D /* Build configuration list for PBXProject "sampleScorllViewInSwift" */;
Expand All @@ -186,7 +123,6 @@
projectRoot = "";
targets = (
7465DED419453DB100AA9A5D /* sampleScorllViewInSwift */,
7465DEE619453DB100AA9A5D /* sampleScorllViewInSwiftTests */,
);
};
/* End PBXProject section */
Expand All @@ -201,13 +137,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
7465DEE519453DB100AA9A5D /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand All @@ -221,24 +150,8 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
7465DEE319453DB100AA9A5D /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7465DEEE19453DB100AA9A5D /* sampleScorllViewInSwiftTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
7465DEE919453DB100AA9A5D /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 7465DED419453DB100AA9A5D /* sampleScorllViewInSwift */;
targetProxy = 7465DEE819453DB100AA9A5D /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
7465DEDE19453DB100AA9A5D /* Main.storyboard */ = {
isa = PBXVariantGroup;
Expand All @@ -259,14 +172,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -307,14 +228,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -349,7 +278,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0.1;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -362,39 +291,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0.1;
};
name = Release;
};
7465DEF519453DB100AA9A5D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/sampleScorllViewInSwift.app/sampleScorllViewInSwift";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = sampleScorllViewInSwiftTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0.1;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Debug;
};
7465DEF619453DB100AA9A5D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/sampleScorllViewInSwift.app/sampleScorllViewInSwift";
INFOPLIST_FILE = sampleScorllViewInSwiftTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "Zuse.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0.1;
TEST_HOST = "$(BUNDLE_LOADER)";
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -419,15 +316,6 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
7465DEF419453DB100AA9A5D /* Build configuration list for PBXNativeTarget "sampleScorllViewInSwiftTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
7465DEF519453DB100AA9A5D /* Debug */,
7465DEF619453DB100AA9A5D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 7465DECD19453DB100AA9A5D /* Project object */;
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

0 comments on commit 8d0965a

Please sign in to comment.