Skip to content

Commit

Permalink
Merge pull request #2 from naeemshaikh90/master
Browse files Browse the repository at this point in the history
Swift 3 Support
  • Loading branch information
yacir committed Mar 8, 2017
2 parents bc9f9ac + a3ab5b1 commit e4c5432
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = "Yassir Barchi";
TargetAttributes = {
FB17358A1C83A0B400EEDB5F = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -267,8 +268,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -311,8 +314,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -331,6 +336,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -345,6 +351,7 @@
PRODUCT_BUNDLE_IDENTIFIER = YB.YBSlantedCollectionViewLayoutSample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -358,6 +365,7 @@
PRODUCT_BUNDLE_IDENTIFIER = YB.YBSlantedCollectionViewLayoutSample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
12 changes: 6 additions & 6 deletions Example/YBSlantedCollectionViewLayoutSample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CustomCollectionCell: YBSlantedCollectionViewCell {
}


func offset(offset: CGPoint) {
imageView.frame = CGRectOffset(self.imageView.bounds, offset.x, offset.y)
func offset(_ offset: CGPoint) {
imageView.frame = self.imageView.bounds.offsetBy(dx: offset.x, dy: offset.y)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,59 @@ class SettingsController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()

self.reverseSlantingDirectionSwitch.on = self.collectionViewLayout.reverseSlantingAngle
self.firstCellSlantingSwitch.on = self.collectionViewLayout.firstCellSlantingEnabled
self.lastCellSlantingSwitch.on = self.collectionViewLayout.lastCellSlantingEnabled
self.scrollDirectionSwitch.on = self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirection.Horizontal
self.reverseSlantingDirectionSwitch.isOn = self.collectionViewLayout.reverseSlantingAngle
self.firstCellSlantingSwitch.isOn = self.collectionViewLayout.firstCellSlantingEnabled
self.lastCellSlantingSwitch.isOn = self.collectionViewLayout.lastCellSlantingEnabled
self.scrollDirectionSwitch.isOn = self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirection.horizontal
self.slantingDeltaSlider.value = Float(self.collectionViewLayout.slantingDelta)
self.lineSpacingSlider.value = Float(self.collectionViewLayout.lineSpacing)


UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Slide)
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.slide)

}

override func prefersStatusBarHidden() -> Bool {
override var prefersStatusBarHidden : Bool {
return false
}

override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
return UIStatusBarAnimation.Slide
override var preferredStatusBarUpdateAnimation : UIStatusBarAnimation {
return UIStatusBarAnimation.slide
}

@IBAction func slantingDirectionChanged(sender: UISwitch) {
self.collectionViewLayout.reverseSlantingAngle = sender.on
@IBAction func slantingDirectionChanged(_ sender: UISwitch) {
self.collectionViewLayout.reverseSlantingAngle = sender.isOn
}

@IBAction func firstCellSlantingSwitchChanged(sender: UISwitch) {
self.collectionViewLayout.firstCellSlantingEnabled = sender.on
@IBAction func firstCellSlantingSwitchChanged(_ sender: UISwitch) {
self.collectionViewLayout.firstCellSlantingEnabled = sender.isOn
}

@IBAction func lastCellSlantingSwitchChanged(sender: UISwitch) {
self.collectionViewLayout.lastCellSlantingEnabled = sender.on
@IBAction func lastCellSlantingSwitchChanged(_ sender: UISwitch) {
self.collectionViewLayout.lastCellSlantingEnabled = sender.isOn
}

@IBAction func scrollDirectionChanged(sender: UISwitch) {
if sender.on {
self.collectionViewLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
@IBAction func scrollDirectionChanged(_ sender: UISwitch) {
if sender.isOn {
self.collectionViewLayout.scrollDirection = UICollectionViewScrollDirection.horizontal
}
else {
self.collectionViewLayout.scrollDirection = UICollectionViewScrollDirection.Vertical
self.collectionViewLayout.scrollDirection = UICollectionViewScrollDirection.vertical
}
self.collectionViewLayout.collectionView?.reloadData()
}


@IBAction func slantingDeltaChanged(sender: UISlider) {
@IBAction func slantingDeltaChanged(_ sender: UISlider) {
self.collectionViewLayout.slantingDelta = UInt(sender.value)
}

@IBAction func lineSpacingChanged(sender: UISlider) {
@IBAction func lineSpacingChanged(_ sender: UISlider) {
self.collectionViewLayout.lineSpacing = CGFloat(sender.value)
}
@IBAction func done(sender: AnyObject) {
self.presentingViewController?.dismissViewControllerAnimated(true, completion: { () -> Void in
self.collectionViewLayout.collectionView?.scrollRectToVisible(CGRectMake(0, 0, 0, 0), animated: true);
@IBAction func done(_ sender: AnyObject) {
self.presentingViewController?.dismiss(animated: true, completion: { () -> Void in
self.collectionViewLayout.collectionView?.scrollRectToVisible(CGRect(x: 0, y: 0, width: 0, height: 0), animated: true);
})
}
}
32 changes: 16 additions & 16 deletions Example/YBSlantedCollectionViewLayoutSample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ class ViewController: UIViewController {
}
}

self.navigationController?.navigationBarHidden = true
self.navigationController?.isNavigationBarHidden = true
}

override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.collectionView.reloadData()
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Slide)
UIApplication.shared.setStatusBarHidden(true, with: UIStatusBarAnimation.slide)
}

override func prefersStatusBarHidden() -> Bool {
override var prefersStatusBarHidden : Bool {
return true
}

override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
return UIStatusBarAnimation.Slide
override var preferredStatusBarUpdateAnimation : UIStatusBarAnimation {
return UIStatusBarAnimation.slide
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ShowSettings" {
let navigation = segue.destinationViewController as! UINavigationController
let navigation = segue.destination as! UINavigationController

let settingsController = navigation.viewControllers[0] as! SettingsController

Expand All @@ -66,14 +66,14 @@ class ViewController: UIViewController {

extension ViewController: UICollectionViewDataSource {

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return images.count
}

func collectionView(collectionView: UICollectionView,
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CustomCollectionCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! CustomCollectionCell

cell.image = images[indexPath.row]

Expand All @@ -83,19 +83,19 @@ extension ViewController: UICollectionViewDataSource {

extension ViewController: UICollectionViewDelegate {

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
NSLog("Did select item at indexPath: [\(indexPath.section)][\(indexPath.row)]")
}
}

extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(scrollView: UIScrollView) {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard let collectionView = self.collectionView else {return}
guard let visibleCells = collectionView.visibleCells() as? [CustomCollectionCell] else {return}
guard let visibleCells = collectionView.visibleCells as? [CustomCollectionCell] else {return}
for parallaxCell in visibleCells {
let yOffset = ((collectionView.contentOffset.y - parallaxCell.frame.origin.y) / parallaxCell.imageHeight) * yOffsetSpeed
let xOffset = ((collectionView.contentOffset.x - parallaxCell.frame.origin.x) / parallaxCell.imageWidth) * xOffsetSpeed
parallaxCell.offset(CGPointMake(xOffset, yOffset))
parallaxCell.offset(CGPoint(x: xOffset,y :yOffset))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ github 'yacir/YBSlantedCollectionViewLayout'
- [x] Improve the attribution of the clic
- [x] Carthage support
- [x] Tests
- [ ] Swift 3 support
- [x] Swift 3 support
- [ ] Swift Package Manager support

## Author
Expand Down
16 changes: 8 additions & 8 deletions Source/YBSlantedCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ import UIKit
YBSlantedCollectionViewCell is a subclass of UICollectionViewCell.
Use it or subclass it to apply the slanting mask on your cells.
*/
public class YBSlantedCollectionViewCell: UICollectionViewCell {
open class YBSlantedCollectionViewCell: UICollectionViewCell {

/// :nodoc:
private var slantedLayerMask: CAShapeLayer?
fileprivate var slantedLayerMask: CAShapeLayer?

/// :nodoc:
override public func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {

if (self.slantedLayerMask != nil) {
let bezierPath = UIBezierPath()
bezierPath.CGPath = self.slantedLayerMask!.path!
let result = bezierPath.containsPoint(point)
bezierPath.cgPath = self.slantedLayerMask!.path!
let result = bezierPath.contains(point)
return result
}

return (super.pointInside(point, withEvent: event))
return (super.point(inside: point, with: event))
}

/// :nodoc:
override public func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes) {
override open func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
let attributes = layoutAttributes as! YBSlantedCollectionViewLayoutAttributes
super.applyLayoutAttributes(attributes)
super.apply(attributes)
self.slantedLayerMask = attributes.slantedLayerMask
self.layer.mask = attributes.slantedLayerMask
}
Expand Down
Loading

0 comments on commit e4c5432

Please sign in to comment.