Skip to content

Commit 73902f2

Browse files
author
Warif Akhand Rishi
committed
Compiled with Xcode 7.1.1
1 parent 5b627e1 commit 73902f2

8 files changed

+36
-28
lines changed

Classes/CKWaveCollectionViewAnimator.swift

+22-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CKWaveCollectionViewAnimator: NSObject, UIViewControllerAnimatedTransition
2323
private let kDeltaBetweenCellLayers: Int! = 2
2424

2525
//MARK :- UIViewControllerAnimatedTransitioning
26-
func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
26+
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
2727
return animationDuration
2828
}
2929

@@ -34,7 +34,12 @@ class CKWaveCollectionViewAnimator: NSObject, UIViewControllerAnimatedTransition
3434

3535
let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)!
3636
let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
37-
let container = transitionContext.containerView()
37+
//let container = transitionContext.containerView()
38+
39+
guard let container = transitionContext.containerView() else {
40+
assertionFailure("containerView is nil")
41+
return
42+
}
3843

3944
container.backgroundColor = UIColor.clearColor()
4045

@@ -126,7 +131,7 @@ class CKWaveCollectionViewAnimator: NSObject, UIViewControllerAnimatedTransition
126131

127132
private func addAnimationsToDestinationCollectionView(destinationCollectionViewController: UICollectionViewController, sourceCollectionViewController: UICollectionViewController, toViewController: UIViewController) {
128133

129-
let indexPaths: NSArray = sourceCollectionViewController.collectionView!.indexPathsForSelectedItems()
134+
let indexPaths: NSArray = sourceCollectionViewController.collectionView!.indexPathsForSelectedItems()!
130135
let selectedCellIndex: NSIndexPath = indexPaths.firstObject as! NSIndexPath
131136
let selectedCell = sourceCollectionViewController.collectionView!.cellForItemAtIndexPath(selectedCellIndex)!
132137

@@ -139,11 +144,11 @@ class CKWaveCollectionViewAnimator: NSObject, UIViewControllerAnimatedTransition
139144

140145
let rowsAndColumns = destinationCollectionViewController.collectionView!.numberOfVisibleRowsAndColumn()
141146

142-
if let indexPathsForVisibleCells = destinationCollectionViewController.collectionView?.indexPathsForVisibleItems() as? Array<NSIndexPath> {
147+
if let indexPathsForVisibleCells = destinationCollectionViewController.collectionView?.indexPathsForVisibleItems() {
143148

144-
let indexPaths = indexPathsForVisibleCells.sorted({ $0.row < $1.row })
149+
let indexPaths = indexPathsForVisibleCells.sort({ $0.row < $1.row })
145150

146-
for (idx, index) in enumerate(indexPaths) {
151+
for (_, index) in indexPaths.enumerate() {
147152

148153
if let cell = destinationCollectionViewController.collectionView?.cellForItemAtIndexPath(NSIndexPath(forRow: index.row, inSection: index.section)) {
149154

@@ -162,8 +167,8 @@ class CKWaveCollectionViewAnimator: NSObject, UIViewControllerAnimatedTransition
162167
//temporary change cell color to selected cell background color
163168
cell.backgroundColor = fromCellColor
164169

165-
var source = sourceCollectionViewController.collectionView
166-
var destination = destinationCollectionViewController.collectionView
170+
let source = sourceCollectionViewController.collectionView
171+
let destination = destinationCollectionViewController.collectionView
167172

168173
if let fromFlowLayout = source?.collectionViewLayout as? UICollectionViewFlowLayout,
169174
toFlowLayout = destination?.collectionViewLayout as? UICollectionViewFlowLayout,
@@ -174,7 +179,7 @@ class CKWaveCollectionViewAnimator: NSObject, UIViewControllerAnimatedTransition
174179
cell.alpha = 1.0
175180
cell.layer.zPosition = kTopCellLayerZIndex - CGFloat(cellIndexPath.row*self.kDeltaBetweenCellLayers)
176181

177-
UIView.animateKeyframesWithDuration(1.0, delay: 0, options: UIViewKeyframeAnimationOptions.allZeros, animations: { () -> Void in
182+
UIView.animateKeyframesWithDuration(1.0, delay: 0, options: UIViewKeyframeAnimationOptions(), animations: { () -> Void in
178183

179184
let relativeStartTime = (self.kCellAnimBigDelta*Double(cellIndexPath.row % rowsAndColumns.columns))
180185

@@ -217,11 +222,11 @@ class CKWaveCollectionViewAnimator: NSObject, UIViewControllerAnimatedTransition
217222

218223
private func setNewFrameToCells(destinationCollectionViewController: UICollectionViewController) {
219224

220-
if let destinationIndexPathsForVisibleCells = destinationCollectionViewController.collectionView?.indexPathsForVisibleItems() as? Array<NSIndexPath> {
225+
if let destinationIndexPathsForVisibleCells = destinationCollectionViewController.collectionView?.indexPathsForVisibleItems() {
221226

222-
let sortedIndexPaths = destinationIndexPathsForVisibleCells.sorted({ $0.row < $1.row })
227+
let sortedIndexPaths = destinationIndexPathsForVisibleCells.sort({ $0.row < $1.row })
223228

224-
for (idx, index) in enumerate(sortedIndexPaths) {
229+
for (_, index) in sortedIndexPaths.enumerate() {
225230

226231
if let cell = destinationCollectionViewController.collectionView?.cellForItemAtIndexPath(index),
227232

@@ -237,15 +242,15 @@ class CKWaveCollectionViewAnimator: NSObject, UIViewControllerAnimatedTransition
237242

238243
assert(destinationCollectionViewController.selectedIndexPath != nil, "Forgot to set selectedIndexPath property?")
239244

240-
var sourceIndexPathsForVisibleCells = sourceCollectionViewController.collectionView?.indexPathsForVisibleItems() as? Array<NSIndexPath>
241-
sourceIndexPathsForVisibleCells!.sort({ $0.row < $1.row })
245+
var sourceIndexPathsForVisibleCells = sourceCollectionViewController.collectionView?.indexPathsForVisibleItems()
246+
sourceIndexPathsForVisibleCells = sourceIndexPathsForVisibleCells!.sort({ $0.row < $1.row })
242247

243248
let rowsAndColumns = destinationCollectionViewController.collectionView!.numberOfVisibleRowsAndColumn()
244249

245-
for (idx, index) in enumerate(sourceIndexPathsForVisibleCells!.reverse()) {
250+
for (idx, index) in sourceIndexPathsForVisibleCells!.reverse().enumerate() {
246251

247252
if let cell = sourceCollectionViewController.collectionView?.cellForItemAtIndexPath(index),
248-
layoutAttributes = sourceCollectionViewController.collectionView?.layoutAttributesForItemAtIndexPath(index),
253+
_ = sourceCollectionViewController.collectionView?.layoutAttributesForItemAtIndexPath(index),
249254
lastSelectedCell = destinationCollectionViewController.collectionView?.cellForItemAtIndexPath(destinationCollectionViewController.selectedIndexPath),
250255
flowLayout = destinationCollectionViewController.collectionView?.collectionViewLayout as? UICollectionViewFlowLayout {
251256

@@ -275,7 +280,7 @@ class CKWaveCollectionViewAnimator: NSObject, UIViewControllerAnimatedTransition
275280
relativeDuration = self.animationDuration - relativeStartTime
276281
}
277282

278-
UIView.animateKeyframesWithDuration(self.animationDuration, delay: 0, options: UIViewKeyframeAnimationOptions.allZeros, animations: { () -> Void in
283+
UIView.animateKeyframesWithDuration(self.animationDuration, delay: 0, options: UIViewKeyframeAnimationOptions(), animations: { () -> Void in
279284

280285
UIView.addKeyframeWithRelativeStartTime(0.0 + (self.kCellAnimSmallDelta * Double(cellIndex)), relativeDuration: self.animationDuration - (self.kCellAnimSmallDelta * Double(cellIndex)), animations: { () -> Void in
281286

Classes/Extensions/UICollectionViewControllerExtension.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension UICollectionViewController {
1919
return objc_getAssociatedObject(self, &selectedIndexPathAssociationKey) as? NSIndexPath
2020
}
2121
set(newValue) {
22-
objc_setAssociatedObject(self, &selectedIndexPathAssociationKey, newValue, objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN))
22+
objc_setAssociatedObject(self, &selectedIndexPathAssociationKey, newValue, .OBJC_ASSOCIATION_RETAIN)
2323
}
2424
}
2525

@@ -30,7 +30,7 @@ extension UICollectionViewController {
3030
}
3131
set(newValue) {
3232
let value = NSValue(CGPoint: newValue)
33-
objc_setAssociatedObject(self, &fromPointAssociationKey, value, objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN))
33+
objc_setAssociatedObject(self, &fromPointAssociationKey, value, .OBJC_ASSOCIATION_RETAIN)
3434
}
3535
}
3636
}

Classes/Extensions/UICollectionViewExtension.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ extension UICollectionView {
1616
var columns = 0
1717
var currentWidth: CGFloat = 0.0
1818

19-
let visibleCells = self.visibleCells() as? Array<UICollectionViewCell>
19+
let visibleCells = self.visibleCells()
2020

21-
for cell in visibleCells! {
21+
for cell in visibleCells {
2222

2323
if (currentWidth + cell.frame.size.width) < self.frame.size.width {
2424
currentWidth += cell.frame.size.width

Example/CKWaveCollectionViewTransition.xcodeproj/project.pbxproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
isa = PBXProject;
140140
attributes = {
141141
LastSwiftUpdateCheck = 0700;
142-
LastUpgradeCheck = 0640;
142+
LastUpgradeCheck = 0710;
143143
ORGANIZATIONNAME = CezaryKopacz;
144144
TargetAttributes = {
145145
ED3335DA1B5407B600AAC193 = {
@@ -239,6 +239,7 @@
239239
COPY_PHASE_STRIP = NO;
240240
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
241241
ENABLE_STRICT_OBJC_MSGSEND = YES;
242+
ENABLE_TESTABILITY = YES;
242243
GCC_C_LANGUAGE_STANDARD = gnu99;
243244
GCC_DYNAMIC_NO_PIC = NO;
244245
GCC_NO_COMMON_BLOCKS = YES;
@@ -306,6 +307,7 @@
306307
INFOPLIST_FILE = CKWaveCollectionViewTransition/Info.plist;
307308
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
308309
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
310+
PRODUCT_BUNDLE_IDENTIFIER = "com.CezaryKopacz.$(PRODUCT_NAME:rfc1034identifier)";
309311
PRODUCT_NAME = CKWaveCollectionViewTransition;
310312
};
311313
name = Debug;
@@ -317,6 +319,7 @@
317319
INFOPLIST_FILE = CKWaveCollectionViewTransition/Info.plist;
318320
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
319321
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
322+
PRODUCT_BUNDLE_IDENTIFIER = "com.CezaryKopacz.$(PRODUCT_NAME:rfc1034identifier)";
320323
PRODUCT_NAME = CKWaveCollectionViewTransition;
321324
};
322325
name = Release;

Example/CKWaveCollectionViewTransition/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
10-
<string>com.CezaryKopacz.$(PRODUCT_NAME:rfc1034identifier)</string>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>

Example/CKWaveCollectionViewTransition/SecondCollectionViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ class SecondCollectionViewController: UICollectionViewController {
1717
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
1818

1919
self.selectedIndexPath = indexPath
20-
var vc = self.storyboard?.instantiateViewControllerWithIdentifier(kThirdVCId) as? ThirdCollectionViewController
20+
let vc = self.storyboard?.instantiateViewControllerWithIdentifier(kThirdVCId) as? ThirdCollectionViewController
2121
self.navigationController?.pushViewController(vc!, animated: true)
2222
}
2323

2424
//MARK :- UICollectionViewDataSource
2525
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
2626

27-
var cell = collectionView.dequeueReusableCellWithReuseIdentifier(kCellId, forIndexPath: indexPath) as! UICollectionViewCell
27+
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(kCellId, forIndexPath: indexPath)
2828
return cell
2929
}
3030

Example/CKWaveCollectionViewTransition/ThirdCollectionViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ThirdCollectionViewController: UICollectionViewController {
2121
//MARK :- UICollectionViewDataSource
2222
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
2323

24-
var cell = collectionView.dequeueReusableCellWithReuseIdentifier(kCellId, forIndexPath: indexPath) as! UICollectionViewCell
24+
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(kCellId, forIndexPath: indexPath)
2525

2626
return cell
2727
}

Example/CKWaveCollectionViewTransition/ViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ class ViewController: UICollectionViewController {
1818

1919
self.selectedIndexPath = indexPath
2020

21-
var vc = self.storyboard?.instantiateViewControllerWithIdentifier(kSecondVCId) as? SecondCollectionViewController
21+
let vc = self.storyboard?.instantiateViewControllerWithIdentifier(kSecondVCId) as? SecondCollectionViewController
2222
self.navigationController?.pushViewController(vc!, animated: true)
2323
}
2424

2525
//MARK :- UICollectionViewDataSource
2626
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
2727

28-
var cell = collectionView.dequeueReusableCellWithReuseIdentifier(kCellId, forIndexPath: indexPath) as! UICollectionViewCell
28+
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(kCellId, forIndexPath: indexPath)
2929
return cell
3030
}
3131

0 commit comments

Comments
 (0)