add NewFeedTypesView

This commit is contained in:
nixzhu
2015-11-25 13:12:28 +08:00
parent 07b88c9d31
commit 3da5d73a2d
3 changed files with 335 additions and 1 deletions
+12
View File
@@ -67,6 +67,7 @@
5018132C1BA3CFEF0025873C /* WeChatActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5018132B1BA3CFEF0025873C /* WeChatActivity.swift */; };
5019F6311B39BFE00000D993 /* ConversationMoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5019F6301B39BFE00000D993 /* ConversationMoreView.swift */; };
502048241B0F1BB3002EBFC7 /* SearchedUsersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 502048231B0F1BB3002EBFC7 /* SearchedUsersViewController.swift */; };
5020B89D1C0576A0006CE8EA /* NewFeedTypesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5020B89C1C0576A0006CE8EA /* NewFeedTypesView.swift */; };
502280F81B1C3F2800E984EE /* FriendsInContactsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 502280F71B1C3F2800E984EE /* FriendsInContactsViewController.swift */; };
5023DE261AB6856300B3EE96 /* ConversationsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5023DE251AB6856300B3EE96 /* ConversationsViewController.swift */; };
5023DE2A1AB685BA00B3EE96 /* ContactsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5023DE291AB685BA00B3EE96 /* ContactsViewController.swift */; };
@@ -414,6 +415,7 @@
5018132B1BA3CFEF0025873C /* WeChatActivity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WeChatActivity.swift; path = Activities/WeChatActivity.swift; sourceTree = "<group>"; };
5019F6301B39BFE00000D993 /* ConversationMoreView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationMoreView.swift; path = Views/ConversationMore/ConversationMoreView.swift; sourceTree = "<group>"; };
502048231B0F1BB3002EBFC7 /* SearchedUsersViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SearchedUsersViewController.swift; path = ViewControllers/SearchedUsers/SearchedUsersViewController.swift; sourceTree = "<group>"; };
5020B89C1C0576A0006CE8EA /* NewFeedTypesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NewFeedTypesView.swift; path = Views/NewFeedTypes/NewFeedTypesView.swift; sourceTree = "<group>"; };
502280F71B1C3F2800E984EE /* FriendsInContactsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FriendsInContactsViewController.swift; path = ViewControllers/FriendsInContacts/FriendsInContactsViewController.swift; sourceTree = "<group>"; };
5023DE251AB6856300B3EE96 /* ConversationsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationsViewController.swift; path = ViewControllers/Conversations/ConversationsViewController.swift; sourceTree = "<group>"; };
5023DE291AB685BA00B3EE96 /* ContactsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ContactsViewController.swift; path = ViewControllers/Contacts/ContactsViewController.swift; sourceTree = "<group>"; };
@@ -993,6 +995,14 @@
name = SearchedUsers;
sourceTree = "<group>";
};
5020B89E1C0576A5006CE8EA /* NewFeedTypes */ = {
isa = PBXGroup;
children = (
5020B89C1C0576A0006CE8EA /* NewFeedTypesView.swift */,
);
name = NewFeedTypes;
sourceTree = "<group>";
};
502280F91B1C3F2F00E984EE /* FriendsInContacts */ = {
isa = PBXGroup;
children = (
@@ -1138,6 +1148,7 @@
50535D1B1BCD19B4002FE1A4 /* TouchClosures */,
50A93A9E1BD8C51D007005DB /* PickerItems */,
6AB0DF5B1BE169030052BED1 /* ShareProfileView */,
5020B89E1C0576A5006CE8EA /* NewFeedTypes */,
);
name = Views;
sourceTree = "<group>";
@@ -2631,6 +2642,7 @@
0A1CAC701AFA481600826B45 /* SkillHomeHeaderView.swift in Sources */,
50AACEC81BB54128004DD54B /* FeedView.swift in Sources */,
0AB8F79A1B15D1DC00F4AF09 /* YepNavigationController.swift in Sources */,
5020B89D1C0576A0006CE8EA /* NewFeedTypesView.swift in Sources */,
502AE53A1AB871C1005BD199 /* YepAlert.swift in Sources */,
5039594E1B05E6E000797A3E /* ProfileSocialAccountGithubCell.swift in Sources */,
5080EB1F1B93F932006F3C2D /* NSBundle+Yep.swift in Sources */,
@@ -24,6 +24,7 @@ class FeedsViewController: BaseViewController {
var filterBarItem: UIBarButtonItem?
lazy var filterView: DiscoverFilterView = DiscoverFilterView()
lazy var newFeedTypesView: NewFeedTypesView = NewFeedTypesView()
lazy var skillTitleView: UIView = {
@@ -402,7 +403,11 @@ class FeedsViewController: BaseViewController {
}
@IBAction func createNewFeed(sender: AnyObject) {
self.performSegueWithIdentifier("presentNewFeed", sender: nil)
if let window = view.window {
newFeedTypesView.showInView(window)
}
//self.performSegueWithIdentifier("presentNewFeed", sender: nil)
}
// MARK: - Navigation
@@ -0,0 +1,317 @@
//
// NewFeedTypesView.swift
// Yep
//
// Created by nixzhu on 15/11/25.
// Copyright © 2015 Catch Inc. All rights reserved.
//
import UIKit
class NewFeedTypeCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
makeUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
lazy var colorTitleLabel: UILabel = {
let label = UILabel()
return label
}()
var colorTitleLabelTextColor: UIColor = UIColor.yepTintColor() {
willSet {
colorTitleLabel.textColor = newValue
}
}
enum FontStyle {
case Light
case Regular
}
var colorTitleLabelFontStyle: FontStyle = .Light {
willSet {
switch newValue {
case .Light:
if #available(iOS 8.2, *) {
colorTitleLabel.font = UIFont.systemFontOfSize(18, weight: UIFontWeightLight)
} else {
colorTitleLabel.font = UIFont(name: "HelveticaNeue-Light", size: 18)!
}
case .Regular:
colorTitleLabel.font = UIFont.systemFontOfSize(18)
}
}
}
func makeUI() {
contentView.addSubview(colorTitleLabel)
colorTitleLabel.translatesAutoresizingMaskIntoConstraints = false
let centerY = NSLayoutConstraint(item: colorTitleLabel, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1, constant: 0)
let centerX = NSLayoutConstraint(item: colorTitleLabel, attribute: .CenterX, relatedBy: .Equal, toItem: contentView, attribute: .CenterX, multiplier: 1, constant: 0)
NSLayoutConstraint.activateConstraints([centerY, centerX])
}
}
class NewFeedTypesView: UIView {
let totalHeight: CGFloat = 60 * 5
lazy var containerView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.clearColor()
return view
}()
lazy var tableView: UITableView = {
let view = UITableView()
view.dataSource = self
view.delegate = self
view.rowHeight = 60
view.scrollEnabled = false
view.registerClass(NewFeedTypeCell.self, forCellReuseIdentifier: "NewFeedTypeCell")
view.registerClass(ConversationMoreColorTitleCell.self, forCellReuseIdentifier: "ConversationMoreColorTitleCell")
return view
}()
var tableViewBottomConstraint: NSLayoutConstraint?
func showInView(view: UIView) {
frame = view.bounds
view.addSubview(self)
layoutIfNeeded()
containerView.alpha = 1
UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseIn, animations: {[weak self] _ in
self?.containerView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)
}, completion: { _ in
})
UIView.animateWithDuration(0.2, delay: 0.1, options: .CurveEaseOut, animations: {[weak self] _ in
self?.tableViewBottomConstraint?.constant = 0
self?.layoutIfNeeded()
}, completion: { _ in
})
}
func hide() {
UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseIn, animations: {[weak self] _ in
if let strongSelf = self {
strongSelf.tableViewBottomConstraint?.constant = strongSelf.totalHeight
}
self?.layoutIfNeeded()
}, completion: { _ in
})
UIView.animateWithDuration(0.2, delay: 0.1, options: .CurveEaseOut, animations: {[weak self] _ in
self?.containerView.backgroundColor = UIColor.clearColor()
}, completion: {[weak self] _ in
self?.removeFromSuperview()
})
}
func hideAndDo(afterHideAction: (() -> Void)?) {
UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveLinear, animations: {[weak self] _ in
self?.containerView.alpha = 0
if let strongSelf = self {
strongSelf.tableViewBottomConstraint?.constant = strongSelf.totalHeight
}
self?.layoutIfNeeded()
}, completion: {[weak self] finished in
self?.removeFromSuperview()
})
delay(0.1) {
afterHideAction?()
}
}
var isFirstTimeBeenAddAsSubview = true
override func didMoveToSuperview() {
super.didMoveToSuperview()
if isFirstTimeBeenAddAsSubview {
isFirstTimeBeenAddAsSubview = false
makeUI()
let tap = UITapGestureRecognizer(target: self, action: "hide")
containerView.addGestureRecognizer(tap)
tap.cancelsTouchesInView = true
tap.delegate = self
}
}
func makeUI() {
addSubview(containerView)
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
let viewsDictionary = [
"containerView": containerView,
"tableView": tableView,
]
// layout for containerView
let containerViewConstraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[containerView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewsDictionary)
let containerViewConstraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:|[containerView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewsDictionary)
NSLayoutConstraint.activateConstraints(containerViewConstraintsH)
NSLayoutConstraint.activateConstraints(containerViewConstraintsV)
// layour for tableView
let tableViewConstraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[tableView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewsDictionary)
let tableViewBottomConstraint = NSLayoutConstraint(item: tableView, attribute: .Bottom, relatedBy: .Equal, toItem: containerView, attribute: .Bottom, multiplier: 1.0, constant: self.totalHeight)
self.tableViewBottomConstraint = tableViewBottomConstraint
let tableViewHeightConstraint = NSLayoutConstraint(item: tableView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: self.totalHeight)
NSLayoutConstraint.activateConstraints(tableViewConstraintsH)
NSLayoutConstraint.activateConstraints([tableViewBottomConstraint, tableViewHeightConstraint])
}
}
// MARK: - UIGestureRecognizerDelegate
extension NewFeedTypesView: UIGestureRecognizerDelegate {
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if touch.view != containerView {
return false
}
return true
}
}
// MARK: - UITableViewDataSource, UITableViewDelegate
extension NewFeedTypesView: UITableViewDataSource, UITableViewDelegate {
enum Row: Int {
case TextPhotos = 0
case Voice
case ShortMovie
case Location
case Cancel
var title: String {
switch self {
case .TextPhotos:
return NSLocalizedString("Text & Photos", comment: "")
case .Voice:
return NSLocalizedString("Voice", comment: "")
case .ShortMovie:
return NSLocalizedString("Short Movie", comment: "")
case .Location:
return NSLocalizedString("Location", comment: "")
case .Cancel:
return NSLocalizedString("Cancel", comment: "")
}
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
guard let row = Row(rawValue: indexPath.row) else {
return UITableViewCell()
}
switch row {
case .Cancel:
let cell = tableView.dequeueReusableCellWithIdentifier("ConversationMoreColorTitleCell") as! ConversationMoreColorTitleCell
cell.colorTitleLabel.text = row.title
cell.colorTitleLabelTextColor = UIColor.yepTintColor()
cell.colorTitleLabelFontStyle = .Light
return cell
default:
let cell = tableView.dequeueReusableCellWithIdentifier("NewFeedTypeCell") as! NewFeedTypeCell
cell.colorTitleLabel.text = row.title
cell.colorTitleLabelTextColor = UIColor.yepTintColor()
cell.colorTitleLabelFontStyle = .Light
return cell
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
if let row = Row(rawValue: indexPath.row) {
switch row {
case .TextPhotos:
hide()
case .Voice:
hide()
case .ShortMovie:
hide()
case .Location:
hide()
case .Cancel:
hide()
}
}
}
}