diff --git a/Onboarding.xcodeproj/project.pbxproj b/Onboarding.xcodeproj/project.pbxproj index 1261ebe..dc9ed44 100644 --- a/Onboarding.xcodeproj/project.pbxproj +++ b/Onboarding.xcodeproj/project.pbxproj @@ -99,7 +99,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = rockwood; TargetAttributes = { E755CDA91CAF236900980DE8 = { @@ -279,6 +279,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.rockwood.Onboarding; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; }; name = Release; diff --git a/Onboarding.xcodeproj/xcshareddata/xcschemes/Onboarding.xcscheme b/Onboarding.xcodeproj/xcshareddata/xcschemes/Onboarding.xcscheme index cd698f7..db4f3a3 100644 --- a/Onboarding.xcodeproj/xcshareddata/xcschemes/Onboarding.xcscheme +++ b/Onboarding.xcodeproj/xcshareddata/xcschemes/Onboarding.xcscheme @@ -1,6 +1,6 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.1 + 1.2 CFBundleSignature ???? CFBundleVersion diff --git a/Sources/NSLayoutConstraint+Convenience.swift b/Sources/NSLayoutConstraint+Convenience.swift index b518cf0..2e2182e 100644 --- a/Sources/NSLayoutConstraint+Convenience.swift +++ b/Sources/NSLayoutConstraint+Convenience.swift @@ -10,41 +10,46 @@ import Foundation import UIKit extension NSLayoutConstraint { - // Apple hasn't bothered to make multiplicitave constraints for anchors that aren't dimensions... - public class func constraintFor(view:UIView, attribute:NSLayoutAttribute, equalToView:UIView, multiplier:CGFloat) -> NSLayoutConstraint { - return NSLayoutConstraint(item: view, - attribute: attribute, - relatedBy: .equal, - toItem: equalToView, - attribute: attribute, - multiplier: multiplier, - constant: 0) + + public class func constraints(for view:UIView, filling:UIView) -> [NSLayoutConstraint] { + return [view.leadingAnchor.constraint(equalTo: filling.leadingAnchor), + view.trailingAnchor.constraint(equalTo: filling.trailingAnchor), + view.topAnchor.constraint(equalTo: filling.topAnchor), + view.bottomAnchor.constraint(equalTo: filling.bottomAnchor)] } +} + +// Apple hasn't bothered to make multiplicitave constraints for anchors that aren't dimensions... +// This weird function signature is working around a compiler bug. +private func con(straint constraint:NSLayoutConstraint, multiplier:CGFloat) -> NSLayoutConstraint { + return NSLayoutConstraint(item: constraint.firstItem, attribute: constraint.firstAttribute, relatedBy: constraint.relation, toItem: constraint.secondItem, attribute: constraint.secondAttribute, multiplier: multiplier, constant: constraint.constant) +} - public class func constraintFor(view:UIView, attribute:NSLayoutAttribute, lessThanOrEqualToView:UIView, multiplier:CGFloat) -> NSLayoutConstraint { - return NSLayoutConstraint(item: view, - attribute: attribute, - relatedBy: .lessThanOrEqual, - toItem: lessThanOrEqualToView, - attribute: attribute, - multiplier: multiplier, - constant: 0) +extension NSLayoutYAxisAnchor { + func constraint(equalTo anchor: NSLayoutAnchor, multiplier:CGFloat) -> NSLayoutConstraint { + return con(straint: super.constraint(equalTo: anchor), multiplier: multiplier) } - public class func constraintFor(view:UIView, attribute:NSLayoutAttribute, greaterThanOrEqualToView:UIView, multiplier:CGFloat) -> NSLayoutConstraint { - return NSLayoutConstraint(item: view, - attribute: attribute, - relatedBy: .greaterThanOrEqual, - toItem: greaterThanOrEqualToView, - attribute: attribute, - multiplier: multiplier, - constant: 0) + func constraint(lessThanOrEqualTo anchor: NSLayoutAnchor, multiplier:CGFloat) -> NSLayoutConstraint { + return con(straint: super.constraint(lessThanOrEqualTo: anchor), multiplier: multiplier) + } + + func constraint(greaterThanOrEqualTo anchor: NSLayoutAnchor, multiplier:CGFloat) -> NSLayoutConstraint { + return con(straint: super.constraint(greaterThanOrEqualTo: anchor), multiplier: multiplier) } +} - public class func constraintsFor(view:UIView, fillingParentView:UIView) -> [NSLayoutConstraint] { - return [view.leadingAnchor.constraint(equalTo: fillingParentView.leadingAnchor), - view.trailingAnchor.constraint(equalTo: fillingParentView.trailingAnchor), - view.topAnchor.constraint(equalTo: fillingParentView.topAnchor), - view.bottomAnchor.constraint(equalTo: fillingParentView.bottomAnchor)] +extension NSLayoutXAxisAnchor { + func constraint(equalTo anchor: NSLayoutAnchor, multiplier:CGFloat) -> NSLayoutConstraint { + return con(straint: super.constraint(equalTo: anchor), multiplier: multiplier) + } + + func constraint(lessThanOrEqualTo anchor: NSLayoutAnchor, multiplier:CGFloat) -> NSLayoutConstraint { + return con(straint: super.constraint(lessThanOrEqualTo: anchor), multiplier: multiplier) + } + + func constraint(greaterThanOrEqualTo anchor: NSLayoutAnchor, multiplier:CGFloat) -> NSLayoutConstraint { + return con(straint: super.constraint(greaterThanOrEqualTo: anchor), multiplier: multiplier) } } + diff --git a/Sources/OnboardingPage.swift b/Sources/OnboardingPage.swift index 40a2a9a..08d7706 100644 --- a/Sources/OnboardingPage.swift +++ b/Sources/OnboardingPage.swift @@ -9,7 +9,7 @@ import UIKit public -protocol OnboardingDoneDelegate { +protocol OnboardingDoneDelegate: AnyObject { func donePressed(_ page:OnboardingPage) } @@ -120,7 +120,7 @@ class OnboardingContentPage : OnboardingPage { backgroundImageView.contentMode = .scaleAspectFill insertSubview(backgroundImageView, at: 0) - NSLayoutConstraint.activate((NSLayoutConstraint.constraintsFor(view: backgroundImageView, fillingParentView: self))) + NSLayoutConstraint.activate((NSLayoutConstraint.constraints(for: backgroundImageView, filling: self))) } private func setupTitleTopStyle() { @@ -148,20 +148,14 @@ class OnboardingContentPage : OnboardingPage { } private func setupTitleSubordinateStyle() { - - NSLayoutConstraint( - item: foregroundImageView, - attribute: .centerY, - relatedBy: .equal, - toItem: self, - attribute: .centerY, - multiplier: 0.66, - constant: 0).isActive = true titleLabel.font = UIFont.systemFont(ofSize: 24) titleLabel.numberOfLines = 0 - NSLayoutConstraint.constraintFor(view: titleLabel, attribute: .centerY, equalToView: self, multiplier: 1.25).isActive = true + NSLayoutConstraint.activate([ + titleLabel.centerYAnchor.constraint(equalTo: centerYAnchor, multiplier: 1.25), + foregroundImageView.centerYAnchor.constraint(equalTo: centerYAnchor, multiplier: 0.66) + ]) setupCommonTitleConstraints() setupCommonForegroundImageConstraints() @@ -231,7 +225,7 @@ class OnboardingFinalPage : OnboardingContentPage { override public func setupConstraints() { super.setupConstraints() - let buttonYConstraint = NSLayoutConstraint.constraintFor(view: doneButton, attribute: .centerY, equalToView: self, multiplier: 1.7) + let buttonYConstraint = doneButton.centerYAnchor.constraint(equalTo: centerYAnchor, multiplier: 1.7) buttonYConstraint.priority = UILayoutPriorityDefaultLow NSLayoutConstraint.activate([ diff --git a/Sources/OnboardingViewController.swift b/Sources/OnboardingViewController.swift index 5471de8..127c6b1 100644 --- a/Sources/OnboardingViewController.swift +++ b/Sources/OnboardingViewController.swift @@ -215,7 +215,7 @@ class OnboardingViewController: UIViewController, UIScrollViewDelegate, Onboardi pager.pageIndicatorTintColor = UIColor.lightGray() overlayView.addSubview(pager) - NSLayoutConstraint.activate(NSLayoutConstraint.constraintsFor(view: overlayView, fillingParentView: view)) + NSLayoutConstraint.activate(NSLayoutConstraint.constraints(for: overlayView, filling: view)) NSLayoutConstraint.activate([ pager.leadingAnchor.constraint(equalTo: overlayView.leadingAnchor), @@ -231,7 +231,7 @@ class OnboardingViewController: UIViewController, UIScrollViewDelegate, Onboardi scroller.showsHorizontalScrollIndicator = false view.addSubview(scroller) - NSLayoutConstraint.activate(NSLayoutConstraint.constraintsFor(view: scroller, fillingParentView: view)) + NSLayoutConstraint.activate(NSLayoutConstraint.constraints(for: scroller, filling: view)) } public func scrollViewDidScroll(_ scrollView: UIScrollView) {