Skip to content

Commit

Permalink
bug fix on removeAllItems
Browse files Browse the repository at this point in the history
  • Loading branch information
terenceLuffy committed Mar 6, 2017
1 parent 48096d8 commit d7bbbc8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions 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.
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -24,7 +24,7 @@ Install using one of the following options:

Swift
```ruby
pod 'ASHorizontalScrollView', '~> 1.5'
pod 'ASHorizontalScrollView', '~> 1.5.1'
```

Objective-C
Expand All @@ -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?
Expand All @@ -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.
Expand Down
13 changes: 8 additions & 5 deletions Sources/ASHorizontalScrollView.swift
Expand Up @@ -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:
*
Expand Down Expand Up @@ -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)
}

/**
Expand All @@ -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
}
Expand Down
Expand Up @@ -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:
*
Expand Down Expand Up @@ -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)
}

/**
Expand All @@ -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
}
Expand Down

0 comments on commit d7bbbc8

Please sign in to comment.