diff --git a/ASHorizontalScrollView.podspec b/ASHorizontalScrollView.podspec index 7bf0a9e..a8eb35b 100644 --- a/ASHorizontalScrollView.podspec +++ b/ASHorizontalScrollView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "ASHorizontalScrollView" - s.version = "1.5" + s.version = "1.5.1" s.summary = "App store style horizontal scroll view" s.description = <<-DESC It acts similar to apps sliding behaviours in App store. There are both Objective-C and Swift version available and they perform exactly the same function, please find whichever you like. @@ -20,7 +20,7 @@ Pod::Spec.new do |s| s.author = { "Weiwei Chen" => "terenceluffy@gmail.com" } s.platform = :ios, "8.0" s.ios.deployment_target = "8.0" - s.source = { :git => 'https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView.git', :tag => "1.5"} + s.source = { :git => 'https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView.git', :tag => "1.5.1"} s.source_files = 'Sources/ASHorizontalScrollView.swift' s.frameworks = 'UIKit' s.requires_arc = true diff --git a/README.md b/README.md index 20e6b4c..be16609 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Install using one of the following options: Swift ```ruby - pod 'ASHorizontalScrollView', '~> 1.5' + pod 'ASHorizontalScrollView', '~> 1.5.1' ``` Objective-C @@ -36,7 +36,7 @@ Install using one of the following options: Swift ```shell - github "terenceLuffy/AppStoreStyleHorizontalScrollView" ~> 1.5 + github "terenceLuffy/AppStoreStyleHorizontalScrollView" ~> 1.5.1 ``` ### How to use it? @@ -54,6 +54,7 @@ Please check in [here](http://terenceluffy.github.io/how-to-use-ASHorizontalScro 1.4: Add custom width when judging whether to scroll to next item; add support to all Apple devices screen size, now you can specified different mini margin, mini appear width and left margin for all sorts of screen sizes. 1.5: 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 +1.5.1: Add checking on items size before removing all items to avoid crash ### iOS Supported Version iOS 8.0 or above. diff --git a/Sources/ASHorizontalScrollView.swift b/Sources/ASHorizontalScrollView.swift index 1cef64b..4693979 100644 --- a/Sources/ASHorizontalScrollView.swift +++ b/Sources/ASHorizontalScrollView.swift @@ -11,6 +11,7 @@ * 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: * @@ -330,10 +331,8 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate { guard let index = self.items.index(of: item) else { return false } - if (index != NSNotFound) { - return self.removeItemAtIndex(index) - } - else {return false} + + return self.removeItemAtIndex(index) } /** @@ -343,12 +342,16 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate { */ open func removeAllItems()->Bool { + if self.items.count == 0 { + return false + } + for i in (0...self.items.count-1).reversed() { let item:UIView = self.items[i] item.removeFromSuperview() } self.items.removeAll(keepingCapacity: false) - self.contentSize = CGSize(width: self.contentSize.width-self.itemsMargin-self.uniformItemSize.width, height: self.frame.size.height) + self.contentSize = self.frame.size return true } diff --git a/sampleScorllViewInSwift/sampleScorllViewInSwift/ASHorizontalScrollView.swift b/sampleScorllViewInSwift/sampleScorllViewInSwift/ASHorizontalScrollView.swift index 1cef64b..4693979 100644 --- a/sampleScorllViewInSwift/sampleScorllViewInSwift/ASHorizontalScrollView.swift +++ b/sampleScorllViewInSwift/sampleScorllViewInSwift/ASHorizontalScrollView.swift @@ -11,6 +11,7 @@ * 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: * @@ -330,10 +331,8 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate { guard let index = self.items.index(of: item) else { return false } - if (index != NSNotFound) { - return self.removeItemAtIndex(index) - } - else {return false} + + return self.removeItemAtIndex(index) } /** @@ -343,12 +342,16 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate { */ open func removeAllItems()->Bool { + if self.items.count == 0 { + return false + } + for i in (0...self.items.count-1).reversed() { let item:UIView = self.items[i] item.removeFromSuperview() } self.items.removeAll(keepingCapacity: false) - self.contentSize = CGSize(width: self.contentSize.width-self.itemsMargin-self.uniformItemSize.width, height: self.frame.size.height) + self.contentSize = self.frame.size return true }