From 497522c11495626aab85e7be225b707d339ef1a6 Mon Sep 17 00:00:00 2001 From: Akkyie Date: Thu, 19 Feb 2015 02:59:04 +0900 Subject: [PATCH 1/5] Adapted for Swift 1.2 --- AKPickerView/AKPickerView.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/AKPickerView/AKPickerView.swift b/AKPickerView/AKPickerView.swift index 3c6fbd6..71b003b 100644 --- a/AKPickerView/AKPickerView.swift +++ b/AKPickerView/AKPickerView.swift @@ -492,8 +492,8 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD } public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCellWithReuseIdentifier(NSStringFromClass(AKCollectionViewCell.self), forIndexPath: indexPath) as AKCollectionViewCell - if let title = self.dataSource?.pickerView?(self, titleForItem: indexPath.item) { + let cell = collectionView.dequeueReusableCellWithReuseIdentifier(NSStringFromClass(AKCollectionViewCell.self), forIndexPath: indexPath) as! AKCollectionViewCell + if let title = self.dataSource?.pickerView?(self, titleForItem: indexPath.item) as? String { cell.label.text = title cell.label.textColor = self.textColor cell.label.highlightedTextColor = self.highlightedTextColor @@ -511,7 +511,6 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD cell.imageView.image = image } cell._selected = (indexPath.item == self.selectedItem) - return cell } From a321c7e78b31e34f21409f294dce464fdbb8abed Mon Sep 17 00:00:00 2001 From: Akkyie Date: Thu, 19 Feb 2015 03:02:54 +0900 Subject: [PATCH 2/5] Changed NSString to String --- AKPickerView/AKPickerView.swift | 14 +++++++------- AKPickerViewSample/ViewController.swift | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AKPickerView/AKPickerView.swift b/AKPickerView/AKPickerView.swift index 71b003b..4b853c3 100644 --- a/AKPickerView/AKPickerView.swift +++ b/AKPickerView/AKPickerView.swift @@ -26,8 +26,8 @@ Protocols to specify the number and type of contents. */ @objc public protocol AKPickerViewDataSource { func numberOfItemsInPickerView(pickerView: AKPickerView) -> Int - optional func pickerView(pickerView: AKPickerView, titleForItem item:Int) -> NSString - optional func pickerView(pickerView: AKPickerView, imageForItem item:Int) -> UIImage + optional func pickerView(pickerView: AKPickerView, titleForItem item: Int) -> String + optional func pickerView(pickerView: AKPickerView, imageForItem item: Int) -> UIImage } // MARK: AKPickerViewDelegate @@ -36,9 +36,9 @@ Protocols to specify the attitude when user selected an item, and customize the appearance of labels. */ @objc public protocol AKPickerViewDelegate: UIScrollViewDelegate { - optional func pickerView(pickerView: AKPickerView, didSelectItem item:Int) - optional func pickerView(pickerView: AKPickerView, marginForItem item:Int) -> CGSize - optional func pickerView(pickerView: AKPickerView, configureLabel label:UILabel, forItem item:Int) + optional func pickerView(pickerView: AKPickerView, didSelectItem item: Int) + optional func pickerView(pickerView: AKPickerView, marginForItem item: Int) -> CGSize + optional func pickerView(pickerView: AKPickerView, configureLabel label: UILabel, forItem item: Int) } // MARK: - Private Classes and Protocols @@ -114,7 +114,7 @@ private class AKCollectionViewCell: UICollectionViewCell { // MARK: AKCollectionViewLayout /** -Private. A subclass of UICollectionViewFlowLayout used in AKPickerView's collection view. +Private. A subclass of UICollectionViewFlowLayout used in the collection view. */ private class AKCollectionViewLayout: UICollectionViewFlowLayout { var delegate: AKCollectionViewLayoutDelegate! @@ -493,7 +493,7 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(NSStringFromClass(AKCollectionViewCell.self), forIndexPath: indexPath) as! AKCollectionViewCell - if let title = self.dataSource?.pickerView?(self, titleForItem: indexPath.item) as? String { + if let title = self.dataSource?.pickerView?(self, titleForItem: indexPath.item) { cell.label.text = title cell.label.textColor = self.textColor cell.label.highlightedTextColor = self.highlightedTextColor diff --git a/AKPickerViewSample/ViewController.swift b/AKPickerViewSample/ViewController.swift index 4e91d30..1d6d2a2 100644 --- a/AKPickerViewSample/ViewController.swift +++ b/AKPickerViewSample/ViewController.swift @@ -41,7 +41,7 @@ class ViewController: UIViewController, AKPickerViewDataSource, AKPickerViewDele uncomment '-pickerView:imageForItem:' to see how it works. */ - func pickerView(pickerView: AKPickerView, titleForItem item: Int) -> NSString { + func pickerView(pickerView: AKPickerView, titleForItem item: Int) -> String { return self.titles[item] } From 529af2031c9f7ff3cf1d18b0cd3a9d56940d68bf Mon Sep 17 00:00:00 2001 From: Akkyie Date: Thu, 19 Feb 2015 03:03:24 +0900 Subject: [PATCH 3/5] Updated podspec to 0.2.0 because of its interface change --- AKPickerView-Swift.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AKPickerView-Swift.podspec b/AKPickerView-Swift.podspec index bffbfcb..73f1b3e 100644 --- a/AKPickerView-Swift.podspec +++ b/AKPickerView-Swift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'AKPickerView-Swift' - s.version = '0.1.3' + s.version = '0.2.0' s.summary = 'A simple yet customizable horizontal picker view.' s.description = 'A simple yet customizable horizontal picker view. Works on iOS 7 / 8' From 669c3d806d6270af37b64e1d9e38fa9dbea70a07 Mon Sep 17 00:00:00 2001 From: Anas AIT ALI Date: Fri, 20 Mar 2015 11:38:34 +0100 Subject: [PATCH 4/5] Fix building errors with swift 1.2 and Xcode 6.3 beta 3 --- AKPickerView/AKPickerView.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AKPickerView/AKPickerView.swift b/AKPickerView/AKPickerView.swift index 4b853c3..6d6ab3f 100644 --- a/AKPickerView/AKPickerView.swift +++ b/AKPickerView/AKPickerView.swift @@ -96,8 +96,8 @@ private class AKCollectionViewCell: UICollectionViewCell { self.contentView.addSubview(self.imageView) } - override init() { - super.init() + init() { + super.init(frame: CGRectZero) self.initialize() } @@ -307,12 +307,12 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD self.collectionView.layer.mask = maskLayer } - override init() { - super.init() + public init() { + super.init(frame: CGRectZero) self.initialize() } - override init(frame: CGRect) { + public override init(frame: CGRect) { super.init(frame: frame) self.initialize() } From cecc26ccccb6a87d8cb5b8b94f9f883b05eb3dfb Mon Sep 17 00:00:00 2001 From: Akkyie Date: Sat, 21 Feb 2015 01:38:49 +0900 Subject: [PATCH 5/5] Added `maskDisabled` property Added setter functions for `maskDisabled` and `viewDepth` so that these properties can be instantly reflected --- AKPickerView/AKPickerView.swift | 50 +++++++++++++++---------- AKPickerViewSample/ViewController.swift | 1 + 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/AKPickerView/AKPickerView.swift b/AKPickerView/AKPickerView.swift index 6d6ab3f..b5de287 100644 --- a/AKPickerView/AKPickerView.swift +++ b/AKPickerView/AKPickerView.swift @@ -246,10 +246,36 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD public lazy var highlightedTextColor = UIColor.blackColor() /// Readwrite. A float value which indicates the spacing between cells. public var interitemSpacing: CGFloat = 0.0 - /// Readwrite. A float value which determines the perspective representation which used when using AKPickerViewStyle.Wheel style. - public var viewDepth: CGFloat = 1000.0 /// Readwrite. The style of the picker view. See AKPickerViewStyle. public var pickerViewStyle = AKPickerViewStyle.Wheel + /// Readwrite. A float value which determines the perspective representation which used when using AKPickerViewStyle.Wheel style. + public var viewDepth: CGFloat = 1000.0 { + didSet { + self.collectionView.layer.sublayerTransform = self.viewDepth > 0.0 ? { + var transform = CATransform3DIdentity; + transform.m34 = -1.0 / self.viewDepth; + return transform; + }() : CATransform3DIdentity; + } + } + /// Readwrite. A boolean value indicates whether the mask is disabled. + public var maskDisabled: Bool! = nil { + didSet { + self.collectionView.layer.mask = self.maskDisabled == true ? nil : { + let maskLayer = CAGradientLayer() + maskLayer.frame = self.collectionView.bounds + maskLayer.colors = [ + UIColor.clearColor().CGColor, + UIColor.blackColor().CGColor, + UIColor.blackColor().CGColor, + UIColor.clearColor().CGColor] + maskLayer.locations = [0.0, 0.33, 0.66, 1.0] + maskLayer.startPoint = CGPointMake(0.0, 0.0) + maskLayer.endPoint = CGPointMake(1.0, 0.0) + return maskLayer + }() + } + } // MARK: Readonly Properties /// Readonly. Index of currently selected item. @@ -294,17 +320,7 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD self.intercepter = AKPickerViewDelegateIntercepter(pickerView: self, delegate: self.delegate) self.collectionView.delegate = self.intercepter - let maskLayer = CAGradientLayer() - maskLayer.frame = self.collectionView.bounds - maskLayer.colors = [ - UIColor.clearColor().CGColor, - UIColor.blackColor().CGColor, - UIColor.blackColor().CGColor, - UIColor.clearColor().CGColor] - maskLayer.locations = [0.0, 0.33, 0.66, 1.0] - maskLayer.startPoint = CGPointMake(0.0, 0.0) - maskLayer.endPoint = CGPointMake(1.0, 0.0) - self.collectionView.layer.mask = maskLayer + self.maskDisabled = self.maskDisabled == nil ? false : self.maskDisabled } public init() { @@ -332,11 +348,7 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD super.layoutSubviews() self.collectionView.collectionViewLayout = self.collectionViewLayout self.scrollToItem(self.selectedItem, animated: false) - self.collectionView.layer.mask.frame = self.collectionView.bounds - - var transform = CATransform3DIdentity; - transform.m34 = -1.0 / max(self.viewDepth, 1.0); - self.collectionView.layer.sublayerTransform = transform; + self.collectionView.layer.mask?.frame = self.collectionView.bounds } public override func intrinsicContentSize() -> CGSize { @@ -570,7 +582,7 @@ public class AKPickerView: UIView, UICollectionViewDataSource, UICollectionViewD self.delegate?.scrollViewDidScroll?(scrollView) CATransaction.begin() CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions) - self.collectionView.layer.mask.frame = self.collectionView.bounds + self.collectionView.layer.mask?.frame = self.collectionView.bounds CATransaction.commit() } diff --git a/AKPickerViewSample/ViewController.swift b/AKPickerViewSample/ViewController.swift index 1d6d2a2..a4b5408 100644 --- a/AKPickerViewSample/ViewController.swift +++ b/AKPickerViewSample/ViewController.swift @@ -24,6 +24,7 @@ class ViewController: UIViewController, AKPickerViewDataSource, AKPickerViewDele self.pickerView.interitemSpacing = 20.0 self.pickerView.viewDepth = 1000.0 self.pickerView.pickerViewStyle = .Wheel + self.pickerView.maskDisabled = false self.pickerView.reloadData() }