diff --git a/ASHorizontalScrollView.podspec b/ASHorizontalScrollView.podspec index da91fa1..5e0292d 100644 --- a/ASHorizontalScrollView.podspec +++ b/ASHorizontalScrollView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "ASHorizontalScrollView" - s.version = "1.1" + s.version = “1.2” 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. @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.homepage = "https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView" s.license = { :type => 'MIT', :text => <<-LICENSE * The MIT License (MIT) - * Copyright (C) 2014-2015 WEIWEI CHEN + * Copyright (C) 2014-2016 WEIWEI CHEN * * 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: * @@ -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.1" } + s.source = { :git => 'https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView.git', :tag => “1.2” } s.source_files = 'Sources/*' s.frameworks = 'UIKit' s.requires_arc = true diff --git a/ASHorizontalScrollViewForObjectiveC.podspec b/ASHorizontalScrollViewForObjectiveC.podspec index a880f46..da3a379 100644 --- a/ASHorizontalScrollViewForObjectiveC.podspec +++ b/ASHorizontalScrollViewForObjectiveC.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "ASHorizontalScrollViewForObjectiveC" - s.version = "1.1" + s.version = "1.2" s.summary = "App store style horizontal scroll view Objective-C" 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. @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.homepage = "https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView" s.license = { :type => 'MIT', :text => <<-LICENSE * The MIT License (MIT) - * Copyright (C) 2014-2015 WEIWEI CHEN + * Copyright (C) 2014-2016 WEIWEI CHEN * * 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: * @@ -20,6 +20,6 @@ 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.1" } + s.source = { :git => 'https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView.git', :tag => "1.2" } s.source_files = 'Sources/ASHorizontalScrollView/*' end diff --git a/README.md b/README.md index 0a55dd0..96bbb4c 100644 --- a/README.md +++ b/README.md @@ -17,19 +17,19 @@ Install using one of the following options: Swift ```ruby - pod 'ASHorizontalScrollView', '~> 1.1' + pod 'ASHorizontalScrollView', '~> 1.2' ``` Objective-C ```ruby - pod 'ASHorizontalScrollViewForObjectiveC', '~> 1.1' + pod 'ASHorizontalScrollViewForObjectiveC', '~> 1.2' ``` 3. Using [Carthage](https://github.com/Carthage/Carthage) Swift ```shell - github "terenceLuffy/AppStoreStyleHorizontalScrollView" ~> 1.1 + github "terenceLuffy/AppStoreStyleHorizontalScrollView" ~> 1.2 ``` ### How to use it? @@ -40,12 +40,14 @@ Please check in [here](http://terenceluffy.github.io/how-to-use-ASHorizontalScro 1.1: Change to adapt iOS 9 and Swift 2.1 +1.2: Change C style code to Swift 3 compatible code, fix removeItemAtIndex last index crash bug + ### iOS Supported Version It is developed based on UIScrollView and its delegate methods, so it is completely compatible to most iOS versions. But the Swift version requires 8.0 or above. ### Authorization The MIT License (MIT) -Copyright (C) 2014-2015 WEIWEI CHEN +Copyright (C) 2014-2016 WEIWEI CHEN 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: diff --git a/ScrollViewSample/ScrollViewSample.xcodeproj/project.xcworkspace/xcuserdata/terencechen.xcuserdatad/UserInterfaceState.xcuserstate b/ScrollViewSample/ScrollViewSample.xcodeproj/project.xcworkspace/xcuserdata/terencechen.xcuserdatad/UserInterfaceState.xcuserstate index 35b0b4a..5e14a50 100644 Binary files a/ScrollViewSample/ScrollViewSample.xcodeproj/project.xcworkspace/xcuserdata/terencechen.xcuserdatad/UserInterfaceState.xcuserstate and b/ScrollViewSample/ScrollViewSample.xcodeproj/project.xcworkspace/xcuserdata/terencechen.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ScrollViewSample/ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.h b/ScrollViewSample/ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.h index 71a612b..1ece134 100644 --- a/ScrollViewSample/ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.h +++ b/ScrollViewSample/ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.h @@ -1,12 +1,13 @@ /* --------------------------------------------------------- * ASHorizontalScrollView.h * The MIT License (MIT) - * Copyright (C) 2014-2015 WEIWEI CHEN + * Copyright (C) 2014-2016 WEIWEI CHEN * --------------------------------------------------------- * History * Created by WEIWEI CHEN on 14-6-1. * Edit by WEIWEI CHEN 14-9-21: fix problems to work on xcode 6.0.1 * Edit by WEIWEI CHEN 15-12-09: add comments on functions + * Edit by WEIWEI CHEN 16-05-17: fix removeItemAtIndex last index crash bug * * * 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: diff --git a/ScrollViewSample/ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m b/ScrollViewSample/ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m index e5dfa79..9caa998 100644 --- a/ScrollViewSample/ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m +++ b/ScrollViewSample/ScrollViewSample/ASHorizontalScrollView/ASHorizontalScrollView.m @@ -1,12 +1,13 @@ /* --------------------------------------------------------- * ASHorizontalScrollView.m * The MIT License (MIT) - * Copyright (C) 2014-2015 WEIWEI CHEN + * Copyright (C) 2014-2016 WEIWEI CHEN * --------------------------------------------------------- * History * Created by WEIWEI CHEN on 14-6-1. * Edit by WEIWEI CHEN 14-9-21: fix problems to work on xcode 6.0.1 * Edit by WEIWEI CHEN 15-12-09: 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: fix removeItemAtIndex last index crash bug * * * 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: @@ -132,9 +133,11 @@ - (BOOL)removeItemAtIndex:(NSInteger)index { if (index < 0 || index > self.items.count-1) return false; //set new x position from index to the end - for (NSInteger i = self.items.count-1; i > index; i--) { - UIView *item = [self.items objectAtIndex:i]; - item.frame = CGRectMake(CGRectGetMinX(item.frame)-self.itemsMargin-self.uniformItemSize.width, CGRectGetMinY(item.frame), CGRectGetWidth(item.frame), CGRectGetHeight(item.frame)); + if (index != self.items.count-1) { + for (NSInteger i = self.items.count-1; i > index; i--) { + UIView *item = [self.items objectAtIndex:i]; + item.frame = CGRectMake(CGRectGetMinX(item.frame)-self.itemsMargin-self.uniformItemSize.width, CGRectGetMinY(item.frame), CGRectGetWidth(item.frame), CGRectGetHeight(item.frame)); + } } UIView *item = [self.items objectAtIndex:index]; [item removeFromSuperview]; diff --git a/Sources/ASHorizontalScrollView.swift b/Sources/ASHorizontalScrollView.swift index 8aae857..f047b72 100644 --- a/Sources/ASHorizontalScrollView.swift +++ b/Sources/ASHorizontalScrollView.swift @@ -1,12 +1,13 @@ /* --------------------------------------------------------- * ASHorizontalScrollView.swift * The MIT License (MIT) -* Copyright (C) 2014-2015 WEIWEI CHEN +* Copyright (C) 2014-2016 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 * * * 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: @@ -146,7 +147,7 @@ public class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate { */ public func removeAllItems()->Bool { - for (var i = self.items.count-1; i >= 0; i--) { + for i in (0...self.items.count-1).reverse() { let item:UIView = self.items[i] item.removeFromSuperview() } @@ -167,10 +168,13 @@ public class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate { { if (index < 0 || index > self.items.count-1) {return false} //set new x position from index to the end - for (var i = self.items.count-1; i > index; i--) { - let item:UIView = self.items[i] - item.frame = CGRectMake(CGRectGetMinX(item.frame)-self.itemsMargin-self.uniformItemSize.width, CGRectGetMinY(item.frame), CGRectGetWidth(item.frame), CGRectGetHeight(item.frame)) + if index != self.items.count-1{ + for i in (index+1...self.items.count-1).reverse() { + let item:UIView = self.items[i] + item.frame = CGRectMake(CGRectGetMinX(item.frame)-self.itemsMargin-self.uniformItemSize.width, CGRectGetMinY(item.frame), CGRectGetWidth(item.frame), CGRectGetHeight(item.frame)) + } } + let item:UIView = self.items[index] item.removeFromSuperview() self.items.removeAtIndex(index) diff --git a/Sources/ASHorizontalScrollView/ASHorizontalScrollView.h b/Sources/ASHorizontalScrollView/ASHorizontalScrollView.h index 71a612b..1ece134 100644 --- a/Sources/ASHorizontalScrollView/ASHorizontalScrollView.h +++ b/Sources/ASHorizontalScrollView/ASHorizontalScrollView.h @@ -1,12 +1,13 @@ /* --------------------------------------------------------- * ASHorizontalScrollView.h * The MIT License (MIT) - * Copyright (C) 2014-2015 WEIWEI CHEN + * Copyright (C) 2014-2016 WEIWEI CHEN * --------------------------------------------------------- * History * Created by WEIWEI CHEN on 14-6-1. * Edit by WEIWEI CHEN 14-9-21: fix problems to work on xcode 6.0.1 * Edit by WEIWEI CHEN 15-12-09: add comments on functions + * Edit by WEIWEI CHEN 16-05-17: fix removeItemAtIndex last index crash bug * * * 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: diff --git a/Sources/ASHorizontalScrollView/ASHorizontalScrollView.m b/Sources/ASHorizontalScrollView/ASHorizontalScrollView.m index e5dfa79..9caa998 100644 --- a/Sources/ASHorizontalScrollView/ASHorizontalScrollView.m +++ b/Sources/ASHorizontalScrollView/ASHorizontalScrollView.m @@ -1,12 +1,13 @@ /* --------------------------------------------------------- * ASHorizontalScrollView.m * The MIT License (MIT) - * Copyright (C) 2014-2015 WEIWEI CHEN + * Copyright (C) 2014-2016 WEIWEI CHEN * --------------------------------------------------------- * History * Created by WEIWEI CHEN on 14-6-1. * Edit by WEIWEI CHEN 14-9-21: fix problems to work on xcode 6.0.1 * Edit by WEIWEI CHEN 15-12-09: 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: fix removeItemAtIndex last index crash bug * * * 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: @@ -132,9 +133,11 @@ - (BOOL)removeItemAtIndex:(NSInteger)index { if (index < 0 || index > self.items.count-1) return false; //set new x position from index to the end - for (NSInteger i = self.items.count-1; i > index; i--) { - UIView *item = [self.items objectAtIndex:i]; - item.frame = CGRectMake(CGRectGetMinX(item.frame)-self.itemsMargin-self.uniformItemSize.width, CGRectGetMinY(item.frame), CGRectGetWidth(item.frame), CGRectGetHeight(item.frame)); + if (index != self.items.count-1) { + for (NSInteger i = self.items.count-1; i > index; i--) { + UIView *item = [self.items objectAtIndex:i]; + item.frame = CGRectMake(CGRectGetMinX(item.frame)-self.itemsMargin-self.uniformItemSize.width, CGRectGetMinY(item.frame), CGRectGetWidth(item.frame), CGRectGetHeight(item.frame)); + } } UIView *item = [self.items objectAtIndex:index]; [item removeFromSuperview]; diff --git a/sampleScorllViewInSwift/sampleScorllViewInSwift.xcodeproj/project.xcworkspace/xcuserdata/terencechen.xcuserdatad/UserInterfaceState.xcuserstate b/sampleScorllViewInSwift/sampleScorllViewInSwift.xcodeproj/project.xcworkspace/xcuserdata/terencechen.xcuserdatad/UserInterfaceState.xcuserstate index 5edbf9d..4581d11 100644 Binary files a/sampleScorllViewInSwift/sampleScorllViewInSwift.xcodeproj/project.xcworkspace/xcuserdata/terencechen.xcuserdatad/UserInterfaceState.xcuserstate and b/sampleScorllViewInSwift/sampleScorllViewInSwift.xcodeproj/project.xcworkspace/xcuserdata/terencechen.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/sampleScorllViewInSwift/sampleScorllViewInSwift.xcodeproj/xcuserdata/terencechen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/sampleScorllViewInSwift/sampleScorllViewInSwift.xcodeproj/xcuserdata/terencechen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index eec3996..cf89800 100644 --- a/sampleScorllViewInSwift/sampleScorllViewInSwift.xcodeproj/xcuserdata/terencechen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/sampleScorllViewInSwift/sampleScorllViewInSwift.xcodeproj/xcuserdata/terencechen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -122,11 +122,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "sampleScorllViewInSwift/ViewController.swift" - timestampString = "471368695.465315" + timestampString = "485185328.013196" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "85" - endingLineNumber = "85" + startingLineNumber = "88" + endingLineNumber = "88" landmarkName = "tableView(_:cellForRowAtIndexPath:)" landmarkType = "5"> diff --git a/sampleScorllViewInSwift/sampleScorllViewInSwift/ASHorizontalScrollView.swift b/sampleScorllViewInSwift/sampleScorllViewInSwift/ASHorizontalScrollView.swift index 8aae857..f047b72 100644 --- a/sampleScorllViewInSwift/sampleScorllViewInSwift/ASHorizontalScrollView.swift +++ b/sampleScorllViewInSwift/sampleScorllViewInSwift/ASHorizontalScrollView.swift @@ -1,12 +1,13 @@ /* --------------------------------------------------------- * ASHorizontalScrollView.swift * The MIT License (MIT) -* Copyright (C) 2014-2015 WEIWEI CHEN +* Copyright (C) 2014-2016 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 * * * 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: @@ -146,7 +147,7 @@ public class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate { */ public func removeAllItems()->Bool { - for (var i = self.items.count-1; i >= 0; i--) { + for i in (0...self.items.count-1).reverse() { let item:UIView = self.items[i] item.removeFromSuperview() } @@ -167,10 +168,13 @@ public class ASHorizontalScrollView: UIScrollView, UIScrollViewDelegate { { if (index < 0 || index > self.items.count-1) {return false} //set new x position from index to the end - for (var i = self.items.count-1; i > index; i--) { - let item:UIView = self.items[i] - item.frame = CGRectMake(CGRectGetMinX(item.frame)-self.itemsMargin-self.uniformItemSize.width, CGRectGetMinY(item.frame), CGRectGetWidth(item.frame), CGRectGetHeight(item.frame)) + if index != self.items.count-1{ + for i in (index+1...self.items.count-1).reverse() { + let item:UIView = self.items[i] + item.frame = CGRectMake(CGRectGetMinX(item.frame)-self.itemsMargin-self.uniformItemSize.width, CGRectGetMinY(item.frame), CGRectGetWidth(item.frame), CGRectGetHeight(item.frame)) + } } + let item:UIView = self.items[index] item.removeFromSuperview() self.items.removeAtIndex(index)