Skip to content

Commit

Permalink
New delegate
Browse files Browse the repository at this point in the history
Refactoring
Clean up
Fix
  • Loading branch information
mtagliafico committed Sep 13, 2016
1 parent b404cce commit e38fbe4
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 224 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -31,3 +31,4 @@ Carthage
# `pod install` in .travis.yml
#
# Pods/
*.xcscmblueprint
4 changes: 3 additions & 1 deletion Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 0 additions & 25 deletions Example/TGLParallaxCarousel/AppDelegate.swift
Expand Up @@ -15,32 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {


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

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) {
// 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) {
// 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) {
// 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) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

2 changes: 1 addition & 1 deletion Example/TGLParallaxCarousel/Base.lproj/Main.storyboard
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
Expand Down
34 changes: 21 additions & 13 deletions Example/TGLParallaxCarousel/CustomView.swift
Expand Up @@ -9,54 +9,62 @@
import UIKit
import TGLParallaxCarousel

@IBDesignable
class CustomView: TGLParallaxCarouselItem {

@IBOutlet weak var numberLabel: UILabel!

// MARK: - outlets
@IBOutlet private weak var numberLabel: UILabel!

// MARK: - properties
private var containerView: UIView!
private let customViewNibName = "CustomView"
private let nibName = "CustomView"

@IBInspectable
var number: Int = 0 {
didSet{
numberLabel.text = "\(number)"
}
}


// MARK: init methods
convenience init(frame: CGRect, number: String) {
// MARK: - init
convenience init(frame: CGRect, number: Int) {
self.init(frame: frame)
numberLabel.text = number
numberLabel.text = "\(number)"
}

override init(frame: CGRect) {
super.init(frame: frame)
xibSetup()
setupUI()
setup()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibSetup()
setupUI()
setup()
}

func xibSetup() {

containerView = loadViewFromNib()
containerView.frame = bounds
containerView.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
addSubview(containerView)
}

func loadViewFromNib() -> UIView {

let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: customViewNibName, bundle: bundle)
let nib = UINib(nibName: nibName, bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}


func setupUI() {
// MARK: - methods
private func setup() {
layer.masksToBounds = false
layer.shadowRadius = 30
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.65

}
}
4 changes: 2 additions & 2 deletions Example/TGLParallaxCarousel/CustomView.xib
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CustomView" customModule="TGLParallaxCarousel_Example" customModuleProvider="target">
<connections>
<outlet property="numberLabel" destination="3ko-Pz-EDc" id="ZGa-UF-nFb"/>
<outlet property="numberLabel" destination="3ko-Pz-EDc" id="IOF-Hq-iem"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
Expand Down
30 changes: 16 additions & 14 deletions Example/TGLParallaxCarousel/ViewController.swift
Expand Up @@ -11,42 +11,44 @@ import TGLParallaxCarousel

class ViewController: UIViewController {

// MARK: - outlets
@IBOutlet weak var carouselView: TGLParallaxCarousel!


// MARK: - view lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setupCarousel()
}

func setupCarousel() {
private func setupCarousel() {
carouselView.delegate = self
carouselView.datasource = self
carouselView.itemMargin = 10
// carouselView.selectedIndex = 2
carouselView.margin = 10
carouselView.selectedIndex = 2
}

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

extension ViewController: TGLParallaxCarouselDatasource {
func numberOfItemsInCarousel(carousel: TGLParallaxCarousel) ->Int {

// MARK: - TGLParallaxCarouselDelegate
extension ViewController: TGLParallaxCarouselDelegate {

func numberOfItemsInCarouselView(carouselView: TGLParallaxCarousel) -> Int {
return 5
}

func viewForItemAtIndex(index: Int, carousel: TGLParallaxCarousel) -> TGLParallaxCarouselItem {
let ratio: CGFloat = view.frame.width / 375.0
return CustomView(frame: CGRectMake(0, 0, 300 * ratio, 150 * ratio), number: "\(index + 1)")
func carouselView(carouselView: TGLParallaxCarousel, itemForRowAtIndex index: Int) -> TGLParallaxCarouselItem {
return CustomView(frame: CGRectMake(0, 0, 300, 150), number: index)
}
}

extension ViewController: TGLParallaxCarouselDelegate {
func didTapOnItemAtIndex(index: Int, carousel: TGLParallaxCarousel) {
func carouselView(carouselView: TGLParallaxCarousel, didSelectItemAtIndex index: Int) {
print("Tap on item at index \(index)")
}

func didMovetoPageAtIndex(index: Int) {
print("Did move to index \(index)")
func carouselView(carouselView: TGLParallaxCarousel, willDisplayItem item: TGLParallaxCarouselItem, forIndex index: Int) {
print("")
}
}

0 comments on commit e38fbe4

Please sign in to comment.