Skip to content

Commit

Permalink
Merge pull request #2 from iCyberon/master
Browse files Browse the repository at this point in the history
iOS 8 Support
  • Loading branch information
mozharovsky authored Aug 16, 2016
2 parents b03e884 + 6801acb commit 1bb8f92
Show file tree
Hide file tree
Showing 14 changed files with 547 additions and 139 deletions.
174 changes: 133 additions & 41 deletions Example/Athlee-Onboarding/Athlee-Onboarding.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import OnboardingKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand Down
Original file line number Diff line number Diff line change
@@ -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="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="16A286a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
Expand All @@ -18,17 +18,17 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0cG-Sg-U6K" customClass="OnboardingView" customModule="Athlee_Onboarding" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="bJ1-mf-N5F">
<rect key="frame" x="536" y="20" width="44" height="33"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<state key="normal" title="NEXT">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0cG-Sg-U6K" customClass="OnboardingView" customModule="OnboardingKit">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import OnboardingKit

public final class DataModel: NSObject, OnboardingViewDelegate, OnboardingViewDataSource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import OnboardingKit

public final class OnboardingViewController: UIViewController {

Expand Down
10 changes: 10 additions & 0 deletions Example/Athlee-Onboarding/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use_frameworks!

target 'Athlee-Onboarding' do
pod 'OnboardingKit', :path => '../../'

target 'Athlee-OnboardingTests' do
inherit! :search_paths

end
end
19 changes: 19 additions & 0 deletions Example/Athlee-Onboarding/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PODS:
- OnboardingKit (0.0.2):
- TZStackView
- TZStackView (1.2.0)

DEPENDENCIES:
- OnboardingKit (from `../../`)

EXTERNAL SOURCES:
OnboardingKit:
:path: ../../

SPEC CHECKSUMS:
OnboardingKit: c37eb2110ca3d8f40fc2ad78e54965b04216a66c
TZStackView: 4b82373b4aabe4d99adf739a34e1bc6755149272

PODFILE CHECKSUM: 4428256f7d1d2fab9e9f0fbe4e8ec9cda004ba00

COCOAPODS: 1.0.1
4 changes: 3 additions & 1 deletion OnboardingKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ Pod::Spec.new do |s|
s.author = { "Eugene Mozharovsky" => "[email protected]" }
s.social_media_url = "http://twitter.com/dottieyottie"
s.platform = :ios, "9.0"
s.ios.deployment_target = "9.0"
s.ios.deployment_target = "8.0"
s.source = { :git => "https://github.com/Athlee/OnboardingKit.git", :tag => s.version }
s.source_files = "Source/*.swift"
s.requires_arc = true

s.dependency 'TZStackView'

end
166 changes: 166 additions & 0 deletions Source/Anchor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
//
// Anchor.swift
// AnchorTest
//
// Created by Jonathan Wight on 7/10/15.
// Copyright © 2015 schwa.io. All rights reserved.
//

#if os(OSX)
import AppKit
internal typealias View = NSView
#elseif os(iOS)
import UIKit
internal typealias View = UIView
#endif

public extension View {
var anchors:Anchors {
return Anchors(item:self)
}
}

public struct Anchors {
internal let item:View

internal init(item:View) {
self.item = item
}

public var leadingAnchor: LayoutXAxisAnchor {
return LayoutXAxisAnchor(item:item, attribute:.Leading)
}
public var trailingAnchor: LayoutXAxisAnchor {
return LayoutXAxisAnchor(item:item, attribute:.Trailing)
}
public var leftAnchor: LayoutXAxisAnchor {
return LayoutXAxisAnchor(item:item, attribute:.Left)
}
public var rightAnchor: LayoutXAxisAnchor {
return LayoutXAxisAnchor(item:item, attribute:.Right)
}
public var topAnchor: LayoutYAxisAnchor {
return LayoutYAxisAnchor(item:item, attribute:.Top)
}
public var bottomAnchor: LayoutYAxisAnchor {
return LayoutYAxisAnchor(item:item, attribute:.Bottom)
}
public var widthAnchor: LayoutDimension {
return LayoutDimension(item:item, attribute:.Width)
}
public var heightAnchor: LayoutDimension {
return LayoutDimension(item:item, attribute:.Height)
}
public var centerXAnchor: LayoutXAxisAnchor {
return LayoutXAxisAnchor(item:item, attribute:.CenterX)
}
public var centerYAnchor: LayoutYAxisAnchor {
return LayoutYAxisAnchor(item:item, attribute:.CenterY)
}
}


// MARK: -

/*
An NSLayoutAnchor represents an edge or dimension of a layout item. Its concrete subclasses allow concise creation of constraints. The idea is that instead of invoking +[NSLayoutConstraint constraintWithItem: attribute: relatedBy: toItem: attribute: multiplier: constant:] directly, you can instead do something like this:

[myView.topAnchor constraintEqualToAnchor:otherView.topAnchor constant:10];

The -constraint* methods are available in multiple flavors to support use of different relations and omission of unused options.

*/

public class LayoutAnchor {

internal var item:View
internal var attribute:NSLayoutAttribute

internal init(item:View, attribute:NSLayoutAttribute) {
self.item = item
self.attribute = attribute
}

// These methods return an inactive constraint of the form thisAnchor = otherAnchor.
public func constraintEqualToAnchor(anchor: LayoutAnchor) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .Equal, toItem: anchor.item, attribute: anchor.attribute, multiplier: 1.0, constant: 0.0)
}

public func constraintGreaterThanOrEqualToAnchor(anchor: LayoutAnchor) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .GreaterThanOrEqual, toItem: anchor.item, attribute: anchor.attribute, multiplier: 1.0, constant: 0.0)
}

public func constraintLessThanOrEqualToAnchor(anchor: LayoutAnchor) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .LessThanOrEqual, toItem: anchor.item, attribute: anchor.attribute, multiplier: 1.0, constant: 0.0)
}

// These methods return an inactive constraint of the form thisAnchor = otherAnchor + constant.
public func constraintEqualToAnchor(anchor: LayoutAnchor, constant c: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .Equal, toItem: anchor.item, attribute: anchor.attribute, multiplier: 1.0, constant: c)
}

public func constraintGreaterThanOrEqualToAnchor(anchor: LayoutAnchor, constant c: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .GreaterThanOrEqual, toItem: anchor.item, attribute: anchor.attribute, multiplier: 1.0, constant: c)
}

public func constraintLessThanOrEqualToAnchor(anchor: LayoutAnchor, constant c: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .LessThanOrEqual, toItem: anchor.item, attribute: anchor.attribute, multiplier: 1.0, constant: c)
}
}

// MARK: -

// Axis-specific subclasses for location anchors: top/bottom, leading/trailing, baseline, etc.
public class LayoutXAxisAnchor : LayoutAnchor {
}

public class LayoutYAxisAnchor : LayoutAnchor {
}

// MARK: -

/*
This layout anchor subclass is used for sizes (width & height).
*/

public class LayoutDimension : LayoutAnchor {

// These methods return an inactive constraint of the form thisVariable = constant.
public func constraintEqualToConstant(c: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .Equal, toItem: nil, attribute:.NotAnAttribute, multiplier: 1.0, constant: c)
}

public func constraintGreaterThanOrEqualToConstant(c: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .GreaterThanOrEqual, toItem: nil, attribute:.NotAnAttribute, multiplier: 1.0, constant: c)
}

public func constraintLessThanOrEqualToConstant(c: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .LessThanOrEqual, toItem: nil, attribute:.NotAnAttribute, multiplier: 1.0, constant: c)
}

// These methods return an inactive constraint of the form thisAnchor = otherAnchor * multiplier.
public func constraintEqualToAnchor(anchor: LayoutDimension, multiplier m: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .Equal, toItem: anchor.item, attribute: anchor.attribute, multiplier: m, constant: 0)
}

public func constraintGreaterThanOrEqualToAnchor(anchor: LayoutDimension, multiplier m: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .GreaterThanOrEqual, toItem: anchor.item, attribute: anchor.attribute, multiplier: m, constant: 0)
}

public func constraintLessThanOrEqualToAnchor(anchor: LayoutDimension, multiplier m: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .LessThanOrEqual, toItem: anchor.item, attribute: anchor.attribute, multiplier: m, constant: 0)
}

// These methods return an inactive constraint of the form thisAnchor = otherAnchor * multiplier + constant.
public func constraintEqualToAnchor(anchor: LayoutDimension, multiplier m: CGFloat, constant c: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .Equal, toItem: anchor.item, attribute: anchor.attribute, multiplier: m, constant: c)
}

public func constraintGreaterThanOrEqualToAnchor(anchor: LayoutDimension, multiplier m: CGFloat, constant c: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .GreaterThanOrEqual, toItem: anchor.item, attribute: anchor.attribute, multiplier: m, constant: c)
}

public func constraintLessThanOrEqualToAnchor(anchor: LayoutDimension, multiplier m: CGFloat, constant c: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(item: item, attribute: attribute, relatedBy: .LessThanOrEqual, toItem: anchor.item, attribute: anchor.attribute, multiplier: m, constant: c)
}
}
56 changes: 39 additions & 17 deletions Source/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,29 @@ public final class OnboardingView: UIView {
insertSubview(pageControlView, atIndex: Int.max)

pageControlView.translatesAutoresizingMaskIntoConstraints = false
bottomPageControlViewAnchor = pageControlView.bottomAnchor.constraintEqualToAnchor(bottomAnchor, constant: -bottomPageControlViewOffset)!

let pageControlViewAnchors = [
pageControlView.leadingAnchor.constraintEqualToAnchor(leadingAnchor, constant: 8),
pageControlView.trailingAnchor.constraintEqualToAnchor(trailingAnchor, constant: -8),
bottomPageControlViewAnchor,
pageControlView.heightAnchor.constraintEqualToConstant(PageControlView.radiusExpanded)
].flatMap { $0 }
if #available(iOS 9.0, *) {
bottomPageControlViewAnchor = pageControlView.bottomAnchor.constraintEqualToAnchor(bottomAnchor, constant: -bottomPageControlViewOffset)!
} else {
bottomPageControlViewAnchor = pageControlView.anchors.bottomAnchor.constraintEqualToAnchor(anchors.bottomAnchor, constant: -bottomPageControlViewOffset)
}

NSLayoutConstraint.activateConstraints(pageControlViewAnchors)
if #available(iOS 9.0, *) {
let pageControlViewAnchors = [
pageControlView.leadingAnchor.constraintEqualToAnchor(leadingAnchor, constant: 8),
pageControlView.trailingAnchor.constraintEqualToAnchor(trailingAnchor, constant: -8),
bottomPageControlViewAnchor,
pageControlView.heightAnchor.constraintEqualToConstant(PageControlView.radiusExpanded)
].flatMap { $0 }
NSLayoutConstraint.activateConstraints(pageControlViewAnchors)
} else {
let pageControlViewAnchors = [
pageControlView.anchors.leadingAnchor.constraintEqualToAnchor(anchors.leadingAnchor, constant: 8),
pageControlView.anchors.trailingAnchor.constraintEqualToAnchor(anchors.trailingAnchor, constant: -8),
bottomPageControlViewAnchor,
pageControlView.anchors.heightAnchor.constraintEqualToConstant(PageControlView.radiusExpanded)
].flatMap { $0 }
NSLayoutConstraint.activateConstraints(pageControlViewAnchors)
}

// Add resture recognizers
addRecognizers()
Expand Down Expand Up @@ -119,14 +132,23 @@ public final class OnboardingView: UIView {

pageView.translatesAutoresizingMaskIntoConstraints = false

let anchors = [
pageView.leadingAnchor.constraintEqualToAnchor(leadingAnchor),
pageView.trailingAnchor.constraintEqualToAnchor(trailingAnchor),
pageView.topAnchor.constraintEqualToAnchor(topAnchor),
pageView.bottomAnchor.constraintEqualToAnchor(bottomAnchor)
].flatMap { $0 }

NSLayoutConstraint.activateConstraints(anchors)
if #available(iOS 9.0, *) {
let anchors = [
pageView.leadingAnchor.constraintEqualToAnchor(leadingAnchor),
pageView.trailingAnchor.constraintEqualToAnchor(trailingAnchor),
pageView.topAnchor.constraintEqualToAnchor(topAnchor),
pageView.bottomAnchor.constraintEqualToAnchor(bottomAnchor)
].flatMap { $0 }
NSLayoutConstraint.activateConstraints(anchors)
} else {
let _anchors = [
pageView.anchors.leadingAnchor.constraintEqualToAnchor(anchors.leadingAnchor),
pageView.anchors.trailingAnchor.constraintEqualToAnchor(anchors.trailingAnchor),
pageView.anchors.topAnchor.constraintEqualToAnchor(anchors.topAnchor),
pageView.anchors.bottomAnchor.constraintEqualToAnchor(anchors.bottomAnchor)
].flatMap { $0 }
NSLayoutConstraint.activateConstraints(_anchors)
}

pageView.configuration = config

Expand Down
Loading

0 comments on commit 1bb8f92

Please sign in to comment.