Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support to disable the transition style for special UINavigationController or UIViewController #72

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
20 changes: 20 additions & 0 deletions Example/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down
64 changes: 59 additions & 5 deletions Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="22n-Re-G8c">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="22n-Re-G8c">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="Xeu-1g-NEa">
<objects>
<navigationController id="22n-Re-G8c" customClass="NavigationController" customModule="KMNavigationBarTransitionExample" customModuleProvider="target" sceneMemberID="viewController">
<navigationController id="22n-Re-G8c" customClass="NavigationController" customModule="KMNavigationBarTransition_Example" customModuleProvider="target" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="tMe-Ck-qEc">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -27,10 +27,59 @@
</objects>
<point key="canvasLocation" x="-852" y="312"/>
</scene>
<!--Present View Controller-->
<scene sceneID="cT1-Yy-2xh">
<objects>
<viewController storyboardIdentifier="PresentViewController" id="ZMt-a0-o3X" customClass="PresentViewController" customModule="KMNavigationBarTransition_Example" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="eEw-cB-Mo8"/>
<viewControllerLayoutGuide type="bottom" id="XTD-xe-rav"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="f2Q-C1-MaH">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="usN-7o-eRe">
<rect key="frame" x="149" y="266" width="76" height="30"/>
<state key="normal" title="pop to root"/>
<connections>
<action selector="popToRootAction:" destination="ZMt-a0-o3X" eventType="touchUpInside" id="c1J-SK-Xi3"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hl7-SQ-Lqx">
<rect key="frame" x="141" y="327" width="92" height="30"/>
<state key="normal" title="pop to penult"/>
<connections>
<action selector="popToPenultAction:" destination="ZMt-a0-o3X" eventType="touchUpInside" id="N5M-s2-2Th"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="t6D-SY-ZbC">
<rect key="frame" x="138" y="388" width="98" height="30"/>
<state key="normal" title="set controllers"/>
<connections>
<action selector="setControllersAction:" destination="ZMt-a0-o3X" eventType="touchUpInside" id="evd-9l-m9q"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="hl7-SQ-Lqx" firstAttribute="top" secondItem="usN-7o-eRe" secondAttribute="bottom" constant="31" id="3n1-gd-TJU"/>
<constraint firstItem="t6D-SY-ZbC" firstAttribute="centerX" secondItem="hl7-SQ-Lqx" secondAttribute="centerX" id="AxH-W2-pfm"/>
<constraint firstItem="usN-7o-eRe" firstAttribute="top" secondItem="eEw-cB-Mo8" secondAttribute="bottom" constant="246" id="Dnx-d3-Lrq"/>
<constraint firstItem="usN-7o-eRe" firstAttribute="centerX" secondItem="f2Q-C1-MaH" secondAttribute="centerX" id="Q6c-Tk-aGC"/>
<constraint firstItem="t6D-SY-ZbC" firstAttribute="top" secondItem="hl7-SQ-Lqx" secondAttribute="bottom" constant="31" id="QFK-k8-wcM"/>
<constraint firstItem="hl7-SQ-Lqx" firstAttribute="centerX" secondItem="usN-7o-eRe" secondAttribute="centerX" id="WOj-WH-Czn"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8go-RV-ogv" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="465" y="-338"/>
</scene>
<!--Settings View Controller-->
<scene sceneID="bPJ-Yw-MC1">
<objects>
<tableViewController id="t1n-FL-Ws1" customClass="SettingsViewController" customModule="KMNavigationBarTransitionExample" customModuleProvider="target" sceneMemberID="viewController">
<tableViewController id="t1n-FL-Ws1" customClass="SettingsViewController" customModule="KMNavigationBarTransition_Example" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="Vq2-f1-7ca">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -59,7 +108,7 @@
<!--Main View Controller-->
<scene sceneID="3pn-vu-HGW">
<objects>
<tableViewController id="CWl-bv-lDg" userLabel="Main View Controller" customClass="MainViewController" customModule="KMNavigationBarTransitionExample" customModuleProvider="target" sceneMemberID="viewController">
<tableViewController id="CWl-bv-lDg" userLabel="Main View Controller" customClass="MainViewController" customModule="KMNavigationBarTransition_Example" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="4d9-n9-jL4">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -215,6 +264,11 @@
</connections>
</tableView>
<navigationItem key="navigationItem" title="Title" id="MtF-iP-tkn">
<barButtonItem key="leftBarButtonItem" title="Present" id="91F-Rf-xpo">
<connections>
<action selector="presentBarButtonAction:" destination="CWl-bv-lDg" id="2iH-fY-REN"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" title="Next" id="Zuu-2P-5wS">
<connections>
<segue destination="CWl-bv-lDg" kind="show" identifier="Show Next" id="gBp-2h-4Hi"/>
Expand Down
27 changes: 27 additions & 0 deletions Example/DisableTransitionNavigationController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// DisableTransitionNavigationController.swift
// KMNavigationBarTransition
//
// Created by Wilson Yuan on 2017/6/21.
// Copyright © 2017年 Zhouqi Mo. All rights reserved.
//

import UIKit

class DisableTransitionNavigationController: UINavigationController {

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
self.km_disableTransition = true
}

override init(rootViewController: UIViewController) {
super.init(rootViewController: rootViewController)
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.km_disableTransition = true
}

}
14 changes: 14 additions & 0 deletions Example/KMNavigationBarTransition-Bridge-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// KMNavigationBarTransition-Bridge-Header.h
// KMNavigationBarTransition
//
// Created by Wilson Yuan on 2017/6/21.
// Copyright © 2017年 Zhouqi Mo. All rights reserved.
//

#ifndef KMNavigationBarTransition_Bridge_Header_h
#define KMNavigationBarTransition_Bridge_Header_h

#import <KMNavigationBarTransition/KMNavigationBarTransition.h>

#endif /* KMNavigationBarTransition_Bridge_Header_h */
7 changes: 7 additions & 0 deletions Example/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class MainViewController: UITableViewController {
navigationController?.setNavigationBarHidden(currentNavigationBarData.prefersHidden, animated: animated)
}

@IBAction func presentBarButtonAction(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: PresentViewController.self))
let controller = storyboard.instantiateViewController(withIdentifier: "PresentViewController")
let navigation = NavigationController(rootViewController: controller)
self.present(navigation, animated: true, completion: nil)
}

}

// MARK: - Target Action
Expand Down
1 change: 0 additions & 1 deletion Example/NavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import UIKit
class NavigationController: UINavigationController {

// MARK: View Life Cycle

override func viewDidLoad() {
super.viewDidLoad()
self.interactivePopGestureRecognizer?.delegate = self
Expand Down
78 changes: 78 additions & 0 deletions Example/PresentViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// PresentViewController.swift
// KMNavigationBarTransition
//
// Created by Wilson Yuan on 2017/6/21.
// Copyright © 2017年 Zhouqi Mo. All rights reserved.
//

import UIKit

class PresentViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(self.leftBarButtonAction))

self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "next", style: .plain, target: self, action: #selector(self.rightBarButtonAction))

}

}

///Action
extension PresentViewController {

func leftBarButtonAction() {
if self.navigationController!.viewControllers.count == 1 {
self.dismiss(animated: true, completion: nil)
}
else {
self.navigationController?.popViewController(animated: true)
}
}

func rightBarButtonAction() {
let controller = presentViewController()
controller.km_disableTransition = true
self.show(controller, sender: nil)
}

@IBAction func popToRootAction(_ sender: Any) {
self.navigationController?.popToRootViewController(animated: true)
}

@IBAction func popToPenultAction(_ sender: Any) {

guard let navigation = self.navigationController,
navigation.viewControllers.count > 2 else {
print("current view controllers count: \(String(describing: self.navigationController?.viewControllers.count))")
return
}

let controller = navigation.viewControllers[navigation.viewControllers.count - 3]
self.navigationController?.popToViewController(controller, animated: true)
}

@IBAction func setControllersAction(_ sender: Any) {

let controller = presentViewController()
controller.view.backgroundColor = UIColor.red
let blueController = presentViewController()
blueController.view.backgroundColor = UIColor.blue
let controllers = [controller, blueController]

self.navigationController?.setViewControllers(controllers, animated: false)
}
}

/// Private method
extension PresentViewController {
fileprivate func presentViewController() -> PresentViewController {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: PresentViewController.self))
let controller = storyboard.instantiateViewController(withIdentifier: "PresentViewController")
return controller as! PresentViewController
}
}
Loading