Skip to content

Commit

Permalink
Adapt Swift 3 and fix bug
Browse files Browse the repository at this point in the history
Change C style code to swift 3 format, fix removeItemAtIndex last index
crash bug
  • Loading branch information
terenceLuffy committed May 17, 2016
1 parent 7cf1046 commit 9a494eb
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 33 deletions.
6 changes: 3 additions & 3 deletions ASHorizontalScrollView.podspec
@@ -1,14 +1,14 @@
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.
DESC
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:
*
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.1" }
s.source = { :git => 'https://github.com/terenceLuffy/AppStoreStyleHorizontalScrollView.git', :tag => “1.2 }
s.source_files = 'Sources/*'
s.frameworks = 'UIKit'
s.requires_arc = true
Expand Down
6 changes: 3 additions & 3 deletions ASHorizontalScrollViewForObjectiveC.podspec
@@ -1,14 +1,14 @@
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.
DESC
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:
*
Expand All @@ -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
10 changes: 6 additions & 4 deletions README.md
Expand Up @@ -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?
Expand All @@ -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:

Expand Down
Binary file not shown.
@@ -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:
Expand Down
@@ -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:
Expand Down Expand Up @@ -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];
Expand Down
14 changes: 9 additions & 5 deletions 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:
Expand Down Expand Up @@ -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()
}
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion 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:
Expand Down
11 changes: 7 additions & 4 deletions 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:
Expand Down Expand Up @@ -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];
Expand Down
Binary file not shown.
Expand Up @@ -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">
</BreakpointContent>
Expand Down
@@ -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:
Expand Down Expand Up @@ -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()
}
Expand All @@ -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)
Expand Down

0 comments on commit 9a494eb

Please sign in to comment.