Skip to content

Commit d7bbbc8

Browse files
committed
bug fix on removeAllItems
1 parent 48096d8 commit d7bbbc8

4 files changed

Lines changed: 21 additions & 14 deletions

File tree

ASHorizontalScrollView.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ASHorizontalScrollView"
3-
s.version = "1.5"
3+
s.version = "1.5.1"
44
s.summary = "App store style horizontal scroll view"
55
s.description = <<-DESC
66
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|
2020
s.author = { "Weiwei Chen" => "terenceluffy@gmail.com" }
2121
s.platform = :ios, "8.0"
2222
s.ios.deployment_target = "8.0"
23-
s.source = { :git => 'https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView.git', :tag => "1.5"}
23+
s.source = { :git => 'https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView.git', :tag => "1.5.1"}
2424
s.source_files = 'Sources/ASHorizontalScrollView.swift'
2525
s.frameworks = 'UIKit'
2626
s.requires_arc = true

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Install using one of the following options:
2424

2525
Swift
2626
```ruby
27-
pod 'ASHorizontalScrollView', '~> 1.5'
27+
pod 'ASHorizontalScrollView', '~> 1.5.1'
2828
```
2929

3030
Objective-C
@@ -36,7 +36,7 @@ Install using one of the following options:
3636

3737
Swift
3838
```shell
39-
github "terenceLuffy/AppStoreStyleHorizontalScrollView" ~> 1.5
39+
github "terenceLuffy/AppStoreStyleHorizontalScrollView" ~> 1.5.1
4040
```
4141

4242
### How to use it?
@@ -54,6 +54,7 @@ Please check in [here](http://terenceluffy.github.io/how-to-use-ASHorizontalScro
5454
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.
5555

5656
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
57+
1.5.1: Add checking on items size before removing all items to avoid crash
5758

5859
### iOS Supported Version
5960
iOS 8.0 or above.

Sources/ASHorizontalScrollView.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* 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
1212
* 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.
1313
* 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
14+
* Edit by WEIWEI CHEN 17-03-03: check items size before removing all items
1415
*
1516
* 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:
1617
*
@@ -330,10 +331,8 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate {
330331
guard let index = self.items.index(of: item) else {
331332
return false
332333
}
333-
if (index != NSNotFound) {
334-
return self.removeItemAtIndex(index)
335-
}
336-
else {return false}
334+
335+
return self.removeItemAtIndex(index)
337336
}
338337

339338
/**
@@ -343,12 +342,16 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate {
343342
*/
344343
open func removeAllItems()->Bool
345344
{
345+
if self.items.count == 0 {
346+
return false
347+
}
348+
346349
for i in (0...self.items.count-1).reversed() {
347350
let item:UIView = self.items[i]
348351
item.removeFromSuperview()
349352
}
350353
self.items.removeAll(keepingCapacity: false)
351-
self.contentSize = CGSize(width: self.contentSize.width-self.itemsMargin-self.uniformItemSize.width, height: self.frame.size.height)
354+
self.contentSize = self.frame.size
352355

353356
return true
354357
}

sampleScorllViewInSwift/sampleScorllViewInSwift/ASHorizontalScrollView.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* 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
1212
* 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.
1313
* 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
14+
* Edit by WEIWEI CHEN 17-03-03: check items size before removing all items
1415
*
1516
* 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:
1617
*
@@ -330,10 +331,8 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate {
330331
guard let index = self.items.index(of: item) else {
331332
return false
332333
}
333-
if (index != NSNotFound) {
334-
return self.removeItemAtIndex(index)
335-
}
336-
else {return false}
334+
335+
return self.removeItemAtIndex(index)
337336
}
338337

339338
/**
@@ -343,12 +342,16 @@ open class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate {
343342
*/
344343
open func removeAllItems()->Bool
345344
{
345+
if self.items.count == 0 {
346+
return false
347+
}
348+
346349
for i in (0...self.items.count-1).reversed() {
347350
let item:UIView = self.items[i]
348351
item.removeFromSuperview()
349352
}
350353
self.items.removeAll(keepingCapacity: false)
351-
self.contentSize = CGSize(width: self.contentSize.width-self.itemsMargin-self.uniformItemSize.width, height: self.frame.size.height)
354+
self.contentSize = self.frame.size
352355

353356
return true
354357
}

0 commit comments

Comments
 (0)