Skip to content

Commit b764e74

Browse files
committed
再造 “手机QQ” 侧滑菜单(四)——增加 TabBar
1 parent a6c777a commit b764e74

File tree

11 files changed

+189
-14
lines changed

11 files changed

+189
-14
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323

2424
![pic](http://lvwenhan.com/content/uploadfile/201504/8f171428840820.gif)
2525

26+
###番外篇:【再造 “手机QQ” 侧滑菜单(四)——增加 TabBar】较简单不再成文。
27+
实现效果:
28+
29+
![pic](http://staticonsae.sinaapp.com/images/9.gif)
30+
2631

2732
有问题请直接在文章下面留言。
2833

SwiftSideslipLikeQQ.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
465933151AD7F60700969878 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 465933131AD7F60700969878 /* LaunchScreen.xib */; };
1717
465933211AD7F60700969878 /* SwiftSideslipLikeQQTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 465933201AD7F60700969878 /* SwiftSideslipLikeQQTests.swift */; };
1818
4659332B1AD7FB0E00969878 /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4659332A1AD7FB0E00969878 /* HomeViewController.swift */; };
19+
46617ED61AF3E4C5008F038F /* MainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46617ED41AF3E4C5008F038F /* MainTabBarController.swift */; };
20+
46617ED71AF3E4C5008F038F /* MainTabBarController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 46617ED51AF3E4C5008F038F /* MainTabBarController.xib */; };
1921
466C00881AD832D9002ED354 /* Common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466C00871AD832D9002ED354 /* Common.swift */; };
2022
466C008D1AD9071A002ED354 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 466C008C1AD9071A002ED354 /* README.md */; };
2123
466C008F1AD92447002ED354 /* LeftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 466C008E1AD92447002ED354 /* LeftViewController.swift */; };
@@ -45,6 +47,8 @@
4547
4659331F1AD7F60700969878 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4648
465933201AD7F60700969878 /* SwiftSideslipLikeQQTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftSideslipLikeQQTests.swift; sourceTree = "<group>"; };
4749
4659332A1AD7FB0E00969878 /* HomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = "<group>"; };
50+
46617ED41AF3E4C5008F038F /* MainTabBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = "<group>"; };
51+
46617ED51AF3E4C5008F038F /* MainTabBarController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainTabBarController.xib; sourceTree = "<group>"; };
4852
466C00871AD832D9002ED354 /* Common.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Common.swift; sourceTree = "<group>"; };
4953
466C008C1AD9071A002ED354 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
5054
466C008E1AD92447002ED354 /* LeftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeftViewController.swift; sourceTree = "<group>"; };
@@ -101,6 +105,8 @@
101105
465933131AD7F60700969878 /* LaunchScreen.xib */,
102106
465933081AD7F60700969878 /* Supporting Files */,
103107
466C00871AD832D9002ED354 /* Common.swift */,
108+
46617ED41AF3E4C5008F038F /* MainTabBarController.swift */,
109+
46617ED51AF3E4C5008F038F /* MainTabBarController.xib */,
104110
);
105111
path = SwiftSideslipLikeQQ;
106112
sourceTree = "<group>";
@@ -212,6 +218,7 @@
212218
files = (
213219
465933101AD7F60700969878 /* Main.storyboard in Resources */,
214220
465933151AD7F60700969878 /* LaunchScreen.xib in Resources */,
221+
46617ED71AF3E4C5008F038F /* MainTabBarController.xib in Resources */,
215222
465933121AD7F60700969878 /* Images.xcassets in Resources */,
216223
);
217224
runOnlyForDeploymentPostprocessing = 0;
@@ -232,6 +239,7 @@
232239
files = (
233240
4642DDB51ADA76DA00D0F32B /* SwiftColors.swift in Sources */,
234241
466C00881AD832D9002ED354 /* Common.swift in Sources */,
242+
46617ED61AF3E4C5008F038F /* MainTabBarController.swift in Sources */,
235243
4659330D1AD7F60700969878 /* ViewController.swift in Sources */,
236244
466C008D1AD9071A002ED354 /* README.md in Sources */,
237245
466C008F1AD92447002ED354 /* LeftViewController.swift in Sources */,

SwiftSideslipLikeQQ.xcodeproj/project.xcworkspace/xcshareddata/SwiftSideslipLikeQQ.xccheckout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
<key>IDESourceControlProjectIdentifier</key>
88
<string>638A92D4-E7ED-492B-A10B-4FBA9A121445</string>
99
<key>IDESourceControlProjectName</key>
10-
<string>SwiftSideslipLikeQQ</string>
10+
<string>project</string>
1111
<key>IDESourceControlProjectOriginsDictionary</key>
1212
<dict>
1313
<key>B50A8E23391344F2DB4CCAF07401A5258B534E2C</key>
1414
<string>github.com:johnlui/SwiftSideslipLikeQQ.git</string>
1515
</dict>
1616
<key>IDESourceControlProjectPath</key>
17-
<string>SwiftSideslipLikeQQ.xcodeproj</string>
17+
<string>SwiftSideslipLikeQQ.xcodeproj/project.xcworkspace</string>
1818
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
1919
<dict>
2020
<key>B50A8E23391344F2DB4CCAF07401A5258B534E2C</key>

SwiftSideslipLikeQQ/Base.lproj/Main.storyboard

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
55
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
66
</dependencies>
77
<scenes>
@@ -264,6 +264,50 @@
264264
</objects>
265265
<point key="canvasLocation" x="1076" y="469"/>
266266
</scene>
267+
<!--联系人-->
268+
<scene sceneID="L9Y-cl-PJI">
269+
<objects>
270+
<viewController storyboardIdentifier="Contacts" title="联系人" id="nBo-Ya-JBc" sceneMemberID="viewController">
271+
<layoutGuides>
272+
<viewControllerLayoutGuide type="top" id="5qT-l7-yly"/>
273+
<viewControllerLayoutGuide type="bottom" id="wl0-up-sXN"/>
274+
</layoutGuides>
275+
<view key="view" contentMode="scaleToFill" id="77m-bO-mbG">
276+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
277+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
278+
<subviews>
279+
<navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="CyB-6H-WdI">
280+
<rect key="frame" x="0.0" y="0.0" width="600" height="64"/>
281+
<constraints>
282+
<constraint firstAttribute="height" constant="64" id="n2x-LQ-0Ov"/>
283+
</constraints>
284+
<items>
285+
<navigationItem title="联系人" id="Qdx-AC-1tx"/>
286+
</items>
287+
</navigationBar>
288+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="联系人" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="e6M-nl-GyN">
289+
<rect key="frame" x="16" y="250" width="568" height="100"/>
290+
<fontDescription key="fontDescription" type="boldSystem" pointSize="40"/>
291+
<color key="textColor" red="0.99607843139999996" green="0.70588235290000001" blue="0.20392156859999999" alpha="1" colorSpace="calibratedRGB"/>
292+
<nil key="highlightedColor"/>
293+
</label>
294+
</subviews>
295+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
296+
<constraints>
297+
<constraint firstItem="CyB-6H-WdI" firstAttribute="leading" secondItem="77m-bO-mbG" secondAttribute="leading" id="6KJ-xs-Agp"/>
298+
<constraint firstItem="wl0-up-sXN" firstAttribute="top" secondItem="e6M-nl-GyN" secondAttribute="bottom" constant="250" id="6VL-Ea-pjQ"/>
299+
<constraint firstItem="e6M-nl-GyN" firstAttribute="centerX" secondItem="CyB-6H-WdI" secondAttribute="centerX" id="Hdq-Ch-Wpi"/>
300+
<constraint firstItem="CyB-6H-WdI" firstAttribute="top" secondItem="77m-bO-mbG" secondAttribute="top" id="KpU-cR-La0"/>
301+
<constraint firstAttribute="trailing" secondItem="CyB-6H-WdI" secondAttribute="trailing" id="Lmz-4P-ysb"/>
302+
<constraint firstItem="e6M-nl-GyN" firstAttribute="centerY" secondItem="77m-bO-mbG" secondAttribute="centerY" id="WaJ-lL-qkc"/>
303+
<constraint firstItem="e6M-nl-GyN" firstAttribute="leading" secondItem="77m-bO-mbG" secondAttribute="leadingMargin" id="jKo-gu-gvY"/>
304+
</constraints>
305+
</view>
306+
</viewController>
307+
<placeholder placeholderIdentifier="IBFirstResponder" id="rzp-Za-cub" userLabel="First Responder" sceneMemberID="firstResponder"/>
308+
</objects>
309+
<point key="canvasLocation" x="1076" y="-300"/>
310+
</scene>
267311
</scenes>
268312
<resources>
269313
<image name="avatar" width="56" height="56"/>

SwiftSideslipLikeQQ/Common.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ import UIKit
1111
struct Common {
1212
static let screenWidth = UIScreen.mainScreen().applicationFrame.maxX
1313
static let screenHeight = UIScreen.mainScreen().applicationFrame.maxY
14+
static let rootViewController = UIApplication.sharedApplication().keyWindow?.rootViewController as! ViewController
15+
static let contactsVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Contacts") as! UIViewController
1416
}

SwiftSideslipLikeQQ/LeftViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class LeftViewController: UIViewController, UITableViewDelegate, UITableViewData
3434
}
3535

3636
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
37-
let viewController = UIApplication.sharedApplication().keyWindow?.rootViewController as! ViewController
38-
37+
let viewController = Common.rootViewController
3938
viewController.homeViewController.titleOfOtherPages = titlesDictionary[indexPath.row]
4039
viewController.homeViewController.performSegueWithIdentifier("showOtherPages", sender: self)
41-
40+
Common.contactsVC.view.removeFromSuperview()
41+
viewController.mainTabBarController.tabBar.hidden = true
42+
viewController.mainTabBarController.selectedIndex = 0
4243
viewController.showHome()
43-
4444
tableView.deselectRowAtIndexPath(indexPath, animated: false)
4545
}
4646

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// MainTabBarController.swift
3+
// SwiftSideslipLikeQQ
4+
//
5+
// Created by JohnLui on 15/5/2.
6+
// Copyright (c) 2015年 com.lvwenhan. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class MainTabBarController: UITabBarController {
12+
13+
override func viewDidLoad() {
14+
super.viewDidLoad()
15+
16+
// Do any additional setup after loading the view.
17+
}
18+
19+
override func didReceiveMemoryWarning() {
20+
super.didReceiveMemoryWarning()
21+
// Dispose of any resources that can be recreated.
22+
}
23+
24+
override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {
25+
switch item.tag {
26+
case 0:
27+
Common.contactsVC.view.removeFromSuperview()
28+
case 1:
29+
Common.rootViewController.mainTabBarController.view.addSubview(Common.contactsVC.view)
30+
Common.rootViewController.mainTabBarController.view.bringSubviewToFront(Common.rootViewController.mainTabBarController.tabBar)
31+
case 2:
32+
println("Just like case 1 ↑")
33+
default:
34+
break
35+
}
36+
}
37+
38+
/*
39+
// MARK: - Navigation
40+
41+
// In a storyboard-based application, you will often want to do a little preparation before navigation
42+
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
43+
// Get the new view controller using segue.destinationViewController.
44+
// Pass the selected object to the new view controller.
45+
}
46+
*/
47+
48+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
5+
</dependencies>
6+
<objects>
7+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MainTabBarController" customModule="SwiftSideslipLikeQQ" customModuleProvider="target"/>
8+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
9+
<tabBarController id="MVf-aK-yqi" customClass="MainTabBarController" customModule="SwiftSideslipLikeQQ" customModuleProvider="target">
10+
<nil key="simulatedBottomBarMetrics"/>
11+
<tabBar key="tabBar" contentMode="scaleToFill" id="3se-QO-4d3">
12+
<rect key="frame" x="0.0" y="0.0" width="320" height="49"/>
13+
<autoresizingMask key="autoresizingMask"/>
14+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
15+
</tabBar>
16+
<viewControllers>
17+
<viewController id="ArV-4A-9pJ">
18+
<layoutGuides>
19+
<viewControllerLayoutGuide type="top" id="2Db-AX-v7B"/>
20+
<viewControllerLayoutGuide type="bottom" id="ols-ay-RfO"/>
21+
</layoutGuides>
22+
<view key="view" contentMode="scaleToFill" id="OZl-hv-SzX">
23+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
24+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
25+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
26+
</view>
27+
<tabBarItem key="tabBarItem" title="消息" image="qq" id="lhs-1a-7cs"/>
28+
</viewController>
29+
<viewController id="dAW-AX-gaf">
30+
<layoutGuides>
31+
<viewControllerLayoutGuide type="top" id="vfC-cQ-9ms"/>
32+
<viewControllerLayoutGuide type="bottom" id="RaY-uK-dmt"/>
33+
</layoutGuides>
34+
<view key="view" contentMode="scaleToFill" id="Wic-8C-sSl">
35+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
36+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
37+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
38+
</view>
39+
<tabBarItem key="tabBarItem" tag="1" systemItem="contacts" id="fje-4a-U9w"/>
40+
</viewController>
41+
<viewController automaticallyAdjustsScrollViewInsets="NO" id="4UF-Yf-2Kt">
42+
<tabBarItem key="tabBarItem" tag="2" title="动态" image="xingxing" id="FSG-M9-Tgi"/>
43+
<toolbarItems/>
44+
</viewController>
45+
</viewControllers>
46+
<point key="canvasLocation" x="236" y="269"/>
47+
</tabBarController>
48+
</objects>
49+
<resources>
50+
<image name="qq" width="30" height="30"/>
51+
<image name="xingxing" width="26" height="27"/>
52+
</resources>
53+
</document>

SwiftSideslipLikeQQ/OtherPageViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class OtherPageViewController: UIViewController {
3535

3636
func goBack() {
3737
self.navigationController?.popViewControllerAnimated(true)
38+
Common.rootViewController.mainTabBarController.tabBar.hidden = false
3839
}
3940

4041
/*

0 commit comments

Comments
 (0)