Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions ScrollTabPageViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = EndouMari;
TargetAttributes = {
4C8C50C81C11B617008A69C9 = {
Expand Down Expand Up @@ -194,13 +194,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
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_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
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 @@ -222,11 +232,12 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -238,13 +249,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
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_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
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 @@ -260,9 +281,11 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_VERSION = 4.2;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
3 changes: 2 additions & 1 deletion ScrollTabPageViewController/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

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

}

39 changes: 22 additions & 17 deletions ScrollTabPageViewController/Classes/ContentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import UIKit
class ContentsView: UIView {

var currentIndex: Int = 0
var tabButtonPressedBlock: ((index: Int) -> Void)?
var scrollDidChangedBlock: ((scroll: CGFloat, shouldScroll: Bool) -> Void)?
var tabButtonPressedBlock: ((_ index: Int) -> Void)?
var scrollDidChangedBlock: ((_ scroll: CGFloat, _ shouldScroll: Bool) -> Void)?

private var scrollStart: CGFloat = 0.0

Expand All @@ -34,14 +34,15 @@ class ContentsView: UIView {
}

private func sharedInit() {
NSBundle.mainBundle().loadNibNamed("ContentsView", owner: self, options: nil)
Bundle.main.loadNibNamed("ContentsView", owner: self, options: nil)
addSubview(contentView)

setupConstraints()

scrollView.delegate = self
scrollView.scrollsToTop = false
}

}


Expand All @@ -50,13 +51,13 @@ class ContentsView: UIView {
extension ContentsView {

private func setupConstraints() {
let topConstraint = NSLayoutConstraint(item: contentView, attribute: .Top, relatedBy: .Equal, toItem: self, attribute: .Top, multiplier: 1.0, constant: 0.0)
let topConstraint = NSLayoutConstraint(item: contentView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 0.0)

let bottomConstraint = NSLayoutConstraint(item: contentView, attribute: .Bottom, relatedBy: .Equal, toItem: self, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
let bottomConstraint = NSLayoutConstraint(item: contentView, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0.0)

let leftConstraint = NSLayoutConstraint(item: contentView, attribute: .Left, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1.0, constant: 0.0)
let leftConstraint = NSLayoutConstraint(item: contentView, attribute: .left, relatedBy: .equal, toItem: self, attribute: .left, multiplier: 1.0, constant: 0.0)

let rightConstraint = NSLayoutConstraint(item: contentView, attribute: .Right, relatedBy: .Equal, toItem: self, attribute: .Right, multiplier: 1.0, constant: 0.0)
let rightConstraint = NSLayoutConstraint(item: contentView, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 0.0)

let constraints = [topConstraint, bottomConstraint, leftConstraint, rightConstraint]

Expand All @@ -65,34 +66,37 @@ extension ContentsView {
}

private func randomColor() -> UIColor {
let red = Float(arc4random_uniform(255)) / 255.0
let green = Float(arc4random_uniform(255)) / 255.0
let blue = Float(arc4random_uniform(255)) / 255.0
return UIColor(colorLiteralRed: red, green: green, blue: blue, alpha: 1.0)
let red = CGFloat(arc4random_uniform(255)) / 255.0
let green = CGFloat(arc4random_uniform(255)) / 255.0
let blue = CGFloat(arc4random_uniform(255)) / 255.0

return UIColor(displayP3Red: red, green: green, blue: blue, alpha: 1.0)
}

func updateCurrentIndex(index: Int, animated: Bool) {
tabButtons[currentIndex].backgroundColor = UIColor.whiteColor()
tabButtons[currentIndex].backgroundColor = UIColor.white
tabButtons[index].backgroundColor = UIColor(red: 0.88, green: 1.0, blue: 0.87, alpha: 1.0)
currentIndex = index
}

}


// MARK: - UIScrollViewDelegate

extension ContentsView: UIScrollViewDelegate {

func scrollViewDidScroll(scrollView: UIScrollView) {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y > 0.0 || frame.minY < 0.0 {
scrollDidChangedBlock?(scroll: scrollView.contentOffset.y, shouldScroll: true)
scrollDidChangedBlock?(scrollView.contentOffset.y, true)
scrollView.contentOffset.y = 0.0
} else {
let scroll = scrollView.contentOffset.y - scrollStart
scrollDidChangedBlock?(scroll: scroll, shouldScroll: false)
scrollDidChangedBlock?(scroll, false)
scrollStart = scrollView.contentOffset.y
}
}

}


Expand All @@ -105,7 +109,8 @@ extension ContentsView {
}

@IBAction private func tabButtonTouchUpInside(button: UIButton) {
tabButtonPressedBlock?(index: button.tag)
updateCurrentIndex(button.tag, animated: true)
tabButtonPressedBlock?(button.tag)
updateCurrentIndex(index: button.tag, animated: true)
}

}
37 changes: 17 additions & 20 deletions ScrollTabPageViewController/Classes/ContentsView.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ContentsView" customModule="ScrollTabPageViewController" customModuleProvider="target">
Expand All @@ -27,15 +31,13 @@
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="I9r-ec-NOx">
<rect key="frame" x="128" y="103" width="64" height="30"/>
<animations/>
<state key="normal" title="Touch"/>
<connections>
<action selector="touchButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="Uxd-fw-nyY"/>
<action selector="touchButtonTouchUpInsideButton:" destination="-1" eventType="touchUpInside" id="7jk-dN-mRh"/>
</connections>
</button>
</subviews>
<animations/>
<color key="backgroundColor" red="0.85098039219999999" green="0.96078431369999995" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.85098039219999999" green="0.96078431369999995" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="I9r-ec-NOx" firstAttribute="top" secondItem="dlF-9e-tCn" secondAttribute="top" constant="103" id="DVZ-e7-rQ1"/>
<constraint firstAttribute="bottom" secondItem="I9r-ec-NOx" secondAttribute="bottom" constant="103" id="Lgq-ae-OJb"/>
Expand All @@ -48,32 +50,29 @@
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="WRh-Ud-SCY">
<rect key="frame" x="0.0" y="0.0" width="160" height="44"/>
<animations/>
<color key="backgroundColor" red="0.85098039215686272" green="1" blue="0.83529411764705885" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.85098039215686272" green="1" blue="0.83529411764705885" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="w4h-3b-RUc"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="tintColor" red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<color key="tintColor" red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<state key="normal" title="first">
<color key="titleColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="tabButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="8x9-bf-hKo"/>
<action selector="tabButtonTouchUpInsideButton:" destination="-1" eventType="touchUpInside" id="C4o-Ol-GlR"/>
</connections>
</button>
<button opaque="NO" tag="1" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="E3f-DU-JbM">
<rect key="frame" x="160" y="0.0" width="160" height="44"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<state key="normal" title="second"/>
<connections>
<action selector="tabButtonTouchUpInside:" destination="-1" eventType="touchUpInside" id="Y0P-Fr-Pvo"/>
<action selector="tabButtonTouchUpInsideButton:" destination="-1" eventType="touchUpInside" id="uI5-yG-bGo"/>
</connections>
</button>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="WRh-Ud-SCY" firstAttribute="height" secondItem="E3f-DU-JbM" secondAttribute="height" id="FLg-lq-hIq"/>
<constraint firstItem="E3f-DU-JbM" firstAttribute="top" secondItem="XOP-Fj-Yt4" secondAttribute="top" id="PVt-gV-43h"/>
Expand All @@ -87,8 +86,7 @@
</constraints>
</view>
</subviews>
<animations/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="XOP-Fj-Yt4" secondAttribute="trailing" id="6Oh-Vk-ZQf"/>
<constraint firstItem="dlF-9e-tCn" firstAttribute="top" secondItem="Kzl-ye-VGt" secondAttribute="top" id="Kra-rk-AoZ"/>
Expand All @@ -101,7 +99,6 @@
</constraints>
</scrollView>
</subviews>
<animations/>
<constraints>
<constraint firstAttribute="bottom" secondItem="Kzl-ye-VGt" secondAttribute="bottom" id="DkP-r8-zfJ"/>
<constraint firstItem="Kzl-ye-VGt" firstAttribute="height" secondItem="zIF-dC-TqL" secondAttribute="height" id="Ec8-8P-AZI"/>
Expand All @@ -112,7 +109,7 @@
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="129" y="346"/>
<point key="canvasLocation" x="206.40000000000001" y="311.24437781109447"/>
</view>
</objects>
</document>
Loading