Skip to content

Commit 6449152

Browse files
committed
Improve code, and adjust relative duration of cell animation.
1 parent ebfb061 commit 6449152

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

Classes/SDENavigationControllerDelegate.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ class SDENavigationControllerDelegate: NSObject, UINavigationControllerDelegate
2020

2121
animationController = SDEPushAndPopAnimationController(operation: operation)
2222
if operation == .Push{
23-
if let toCollectionVC = toVC as? UICollectionViewController{
23+
if let fromCollectionVC = fromVC as? UICollectionViewController, let toCollectionVC = toVC as? UICollectionViewController{
24+
let layoutAttributes = fromCollectionVC.collectionView?.layoutAttributesForItemAtIndexPath(fromCollectionVC.selectedIndexPath)
25+
let areaRect = fromCollectionVC.collectionView!.convertRect(layoutAttributes!.frame, toView: fromCollectionVC.collectionView?.superview)
26+
toCollectionVC.areaRectInSuperview = areaRect
2427
interactionController = SDEPopPinchInteractionController(toVC: toCollectionVC, holder: self)
2528
}
2629
}

Classes/SDEPushAndPopAnimationController.swift

+4-10
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,17 @@ class SDEPushAndPopAnimationController: NSObject, UIViewControllerAnimatedTransi
160160
let columns = verticalCount
161161

162162
let relativeStartTime = (self.kCellAnimationBigDelta * Double(indexPath.row % columns))
163-
var relativeDuration = 0.5 - (self.kCellAnimationSmallDelta * Double(indexPath.row))
164-
if (relativeStartTime + relativeDuration) > 0.5 {
165-
relativeDuration = 0.5 - relativeStartTime
166-
}
163+
let relativeDuration = 0.5 - (self.kCellAnimationSmallDelta * Double(indexPath.row))
167164

168165
UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0.7, animations: {
169166
cell.alpha = 1
170167
})
171168

172-
UIView.addKeyframeWithRelativeStartTime(0.5 + relativeStartTime, relativeDuration: 0.3, animations: {
169+
UIView.addKeyframeWithRelativeStartTime(0.5 + relativeStartTime, relativeDuration: relativeDuration, animations: {
173170
cell.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1)
174171
})
175172

176-
UIView.addKeyframeWithRelativeStartTime(0.5 + relativeStartTime, relativeDuration: 0.3, animations: {
173+
UIView.addKeyframeWithRelativeStartTime(0.5 + relativeStartTime, relativeDuration: relativeDuration, animations: {
177174
cell.center = layoutAttributes!.center
178175
})
179176

@@ -271,10 +268,7 @@ class SDEPushAndPopAnimationController: NSObject, UIViewControllerAnimatedTransi
271268
let heightScale = cellHeight / cell.frame.height
272269

273270
let relativeStartTime = (self.kCellAnimationBigDelta * Double(relativeRow % verticalCount))
274-
var relativeDuration = 0.5 - (self.kCellAnimationSmallDelta * Double(relativeRow))
275-
if (relativeStartTime + relativeDuration) > 0.5 {
276-
relativeDuration = 0.5 - relativeStartTime
277-
}
271+
let relativeDuration = 0.5 - (self.kCellAnimationSmallDelta * Double(relativeRow))
278272

279273
UIView.addKeyframeWithRelativeStartTime(relativeStartTime, relativeDuration: relativeDuration, animations: {
280274
cell.center = CGPoint(x: centerX, y: centerY)

Example/Main.storyboard

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="Ej0-qV-deg">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="Ej0-qV-deg">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
66
</dependencies>
77
<scenes>
88
<!--Navigation Controller-->

Example/SDEGalleriesViewController.swift

-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ class SDEGalleriesViewController: UICollectionViewController, PHPhotoLibraryChan
214214
self.selectedIndexPath = indexPath
215215

216216
let layoutAttributes = self.collectionView!.layoutAttributesForItemAtIndexPath(indexPath)
217-
let areaRect = self.collectionView!.convertRect(layoutAttributes!.frame, toView: self.collectionView!.superview)
218217

219218
let circleView = UIView(frame: CGRectMake(0, 0, 30.0, 30.0))
220219
circleView.layer.cornerRadius = 15.0
@@ -232,7 +231,6 @@ class SDEGalleriesViewController: UICollectionViewController, PHPhotoLibraryChan
232231
if let albumVC = self.storyboard?.instantiateViewControllerWithIdentifier("AlbumVC") as? SDEAlbumViewController{
233232
let assetCollection = self.dataSource[indexPath.section][indexPath.row]
234233
albumVC.assetCollection = assetCollection
235-
albumVC.areaRectInSuperview = areaRect
236234
self.navigationController?.pushViewController(albumVC, animated: true)
237235
}
238236
})

0 commit comments

Comments
 (0)