From d64a45cadd1bd9e6afd2cf930548707c981d5777 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 22 Jul 2015 17:16:40 +0800 Subject: [PATCH 1/4] add pod Ruler --- Podfile | 1 + Podfile.lock | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Podfile b/Podfile index 6d3ea629..43263c35 100644 --- a/Podfile +++ b/Podfile @@ -2,6 +2,7 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks! +pod 'Ruler' pod 'Proposer' pod 'APAddressBook/Swift' pod 'FXBlurView' diff --git a/Podfile.lock b/Podfile.lock index 8e34543e..aee96172 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -36,6 +36,7 @@ PODS: - Realm/Headers (0.93.2) - RealmSwift (0.93.2): - Realm (= 0.93.2) + - Ruler (0.5) - SocketRocket (0.4) - TPKeyboardAvoiding (1.2.8) @@ -48,6 +49,7 @@ DEPENDENCIES: - pop - Proposer - RealmSwift + - Ruler - TPKeyboardAvoiding (~> 1.2) EXTERNAL SOURCES: @@ -65,7 +67,8 @@ SPEC CHECKSUMS: Proposer: 6fa2c0dc88b5445aed16786c6717d3676586ff9b Realm: 2fdd0ae74f730e190384e0338d8a0d3654df8220 RealmSwift: 231b064da9f98b1c4f325fe1f1cb8756aae2b8d6 + Ruler: bf01a372f064c900c089c78abd75c2685a86ecba SocketRocket: 01443933b7bc362621325f4607b80b4286a99707 TPKeyboardAvoiding: f1ef0028fe9ba98ef2871cf55b4bbc39cae0267b -COCOAPODS: 0.37.2 +COCOAPODS: 0.38.0 From 3ac46f534f34b4ee1902dbc8d57fc3ab77a9d562 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 22 Jul 2015 17:31:20 +0800 Subject: [PATCH 2/4] use Ruler --- Yep/Configs/YepConfig.swift | 9 +++++---- Yep/Extensions/UIImage+Yep.swift | 3 ++- .../EditNicknameAndBadgeViewController.swift | 3 ++- .../Login/LoginByMobileViewController.swift | 5 +++-- .../Login/LoginVerifyMobileViewController.swift | 7 ++++--- .../Register/RegisterPickMobileViewController.swift | 5 +++-- .../Register/RegisterPickNameViewController.swift | 5 +++-- .../Register/RegisterVerifyMobileViewController.swift | 7 ++++--- 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Yep/Configs/YepConfig.swift b/Yep/Configs/YepConfig.swift index 0568d73b..c7431915 100644 --- a/Yep/Configs/YepConfig.swift +++ b/Yep/Configs/YepConfig.swift @@ -7,6 +7,7 @@ // import UIKit +import Ruler class YepConfig { @@ -86,7 +87,7 @@ class YepConfig { } struct Profile { - static let leftEdgeInset: CGFloat = UIDevice.matchWidthFrom(20, 38, 40) + static let leftEdgeInset: CGFloat = Ruler.match(.iPhoneWidths(20, 38, 40)) static let rightEdgeInset: CGFloat = leftEdgeInset static let introductionLabelFont = UIFont(name: "Helvetica-Light", size: 14)! } @@ -105,7 +106,7 @@ class YepConfig { struct SocialWorkGithub { struct Repo { - static let leftEdgeInset = UIDevice.matchWidthFrom(20, 38, 40) + static let leftEdgeInset = Ruler.match(.iPhoneWidths(20, 38, 40)) static let rightEdgeInset = leftEdgeInset } } @@ -117,8 +118,8 @@ class YepConfig { struct ChatCell { static let gapBetweenDotImageViewAndBubble: CGFloat = 5 - static let mediaPreferredWidth: CGFloat = UIDevice.matchWidthFrom(192, 225, 250) - static let mediaPreferredHeight: CGFloat = UIDevice.matchWidthFrom(208, 244, 270) + static let mediaPreferredWidth: CGFloat = Ruler.match(.iPhoneWidths(192, 225, 250)) + static let mediaPreferredHeight: CGFloat = Ruler.match(.iPhoneWidths(208, 244, 270)) static let mediaMinWidth: CGFloat = 60 static let mediaMinHeight: CGFloat = 30 diff --git a/Yep/Extensions/UIImage+Yep.swift b/Yep/Extensions/UIImage+Yep.swift index f132b9a5..bd229bd7 100644 --- a/Yep/Extensions/UIImage+Yep.swift +++ b/Yep/Extensions/UIImage+Yep.swift @@ -7,11 +7,12 @@ // import UIKit +import Ruler extension UIImage { func roundImageOfRadius(radius: CGFloat) -> UIImage { - let radius = floor(radius - UIDevice.matchWidthFrom(0.5, 0.5, 1.5)) + let radius = floor(radius - Ruler.match(.iPhoneWidths(0.5, 0.5, 1.5))) return self.largestCenteredSquareImage().resizeToTargetSize(CGSize(width: radius * 2, height: radius * 2)).roundImage() } diff --git a/Yep/ViewControllers/EditNicknameAndBadge/EditNicknameAndBadgeViewController.swift b/Yep/ViewControllers/EditNicknameAndBadge/EditNicknameAndBadgeViewController.swift index c8df0450..b9f75e87 100644 --- a/Yep/ViewControllers/EditNicknameAndBadge/EditNicknameAndBadgeViewController.swift +++ b/Yep/ViewControllers/EditNicknameAndBadge/EditNicknameAndBadgeViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Ruler class EditNicknameAndBadgeViewController: UITableViewController { @@ -49,7 +50,7 @@ class EditNicknameAndBadgeViewController: UITableViewController { nicknameTextField.text = YepUserDefaults.nickname.value nicknameTextField.delegate = self - let gap = UIDevice.matchWidthFrom(10, 25, 32) + let gap = Ruler.match(.iPhoneWidths(10, 25, 32)) centerLeft1GapConstraint.constant = gap centerRight1GapConstraint.constant = gap left1Left2GapConstraint.constant = gap diff --git a/Yep/ViewControllers/Login/LoginByMobileViewController.swift b/Yep/ViewControllers/Login/LoginByMobileViewController.swift index 8113d5bf..5b45ee0e 100644 --- a/Yep/ViewControllers/Login/LoginByMobileViewController.swift +++ b/Yep/ViewControllers/Login/LoginByMobileViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Ruler class LoginByMobileViewController: UIViewController { @@ -41,8 +42,8 @@ class LoginByMobileViewController: UIViewController { mobileNumberTextField.delegate = self mobileNumberTextField.addTarget(self, action: "textFieldDidChange:", forControlEvents: .EditingChanged) - pickMobileNumberPromptLabelTopConstraint.constant = UIDevice.matchFrom(30, 50, 60, 60) - mobileNumberTextFieldTopConstraint.constant = UIDevice.matchFrom(30, 40, 50, 50) + pickMobileNumberPromptLabelTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 50, 60, 60)) + mobileNumberTextFieldTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 40, 50, 50)) } override func viewWillAppear(animated: Bool) { diff --git a/Yep/ViewControllers/Login/LoginVerifyMobileViewController.swift b/Yep/ViewControllers/Login/LoginVerifyMobileViewController.swift index 8539574e..d237b3cc 100644 --- a/Yep/ViewControllers/Login/LoginVerifyMobileViewController.swift +++ b/Yep/ViewControllers/Login/LoginVerifyMobileViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Ruler class LoginVerifyMobileViewController: UIViewController { @@ -59,9 +60,9 @@ class LoginVerifyMobileViewController: UIViewController { callMePromptLabel.text = NSLocalizedString("Didn't get it?", comment: "") callMeButton.setTitle(NSLocalizedString("Call me", comment: ""), forState: .Normal) - verifyMobileNumberPromptLabelTopConstraint.constant = UIDevice.matchFrom(30, 50, 60, 60) - verifyCodeTextFieldTopConstraint.constant = UIDevice.matchFrom(30, 40, 50, 50) - callMeButtonTopConstraint.constant = UIDevice.matchFrom(10, 20, 40, 40) + verifyMobileNumberPromptLabelTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 50, 60, 60)) + verifyCodeTextFieldTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 40, 50, 50)) + callMeButtonTopConstraint.constant = Ruler.match(.iPhoneHeights(10, 20, 40, 40)) } override func viewWillAppear(animated: Bool) { diff --git a/Yep/ViewControllers/Register/RegisterPickMobileViewController.swift b/Yep/ViewControllers/Register/RegisterPickMobileViewController.swift index f0cd25e7..7b22dd79 100644 --- a/Yep/ViewControllers/Register/RegisterPickMobileViewController.swift +++ b/Yep/ViewControllers/Register/RegisterPickMobileViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Ruler class RegisterPickMobileViewController: UIViewController { @@ -41,8 +42,8 @@ class RegisterPickMobileViewController: UIViewController { mobileNumberTextField.delegate = self mobileNumberTextField.addTarget(self, action: "textFieldDidChange:", forControlEvents: .EditingChanged) - pickMobileNumberPromptLabelTopConstraint.constant = UIDevice.matchFrom(30, 50, 60, 60) - mobileNumberTextFieldTopConstraint.constant = UIDevice.matchFrom(30, 40, 50, 50) + pickMobileNumberPromptLabelTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 50, 60, 60)) + mobileNumberTextFieldTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 40, 50, 50)) } override func viewWillAppear(animated: Bool) { diff --git a/Yep/ViewControllers/Register/RegisterPickNameViewController.swift b/Yep/ViewControllers/Register/RegisterPickNameViewController.swift index 2fdf7850..f01844a7 100644 --- a/Yep/ViewControllers/Register/RegisterPickNameViewController.swift +++ b/Yep/ViewControllers/Register/RegisterPickNameViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Ruler class RegisterPickNameViewController: UIViewController { @@ -33,8 +34,8 @@ class RegisterPickNameViewController: UIViewController { nameTextField.delegate = self nameTextField.addTarget(self, action: "textFieldDidChange:", forControlEvents: .EditingChanged) - pickNamePromptLabelTopConstraint.constant = UIDevice.matchFrom(30, 50, 60, 60) - nameTextFieldTopConstraint.constant = UIDevice.matchFrom(30, 40, 50, 50) + pickNamePromptLabelTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 50, 60, 60)) + nameTextFieldTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 40, 50, 50)) } override func viewWillAppear(animated: Bool) { diff --git a/Yep/ViewControllers/Register/RegisterVerifyMobileViewController.swift b/Yep/ViewControllers/Register/RegisterVerifyMobileViewController.swift index c0fc6c90..18531b8a 100644 --- a/Yep/ViewControllers/Register/RegisterVerifyMobileViewController.swift +++ b/Yep/ViewControllers/Register/RegisterVerifyMobileViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Ruler class RegisterVerifyMobileViewController: UIViewController { @@ -59,9 +60,9 @@ class RegisterVerifyMobileViewController: UIViewController { callMePromptLabel.text = NSLocalizedString("Didn't get it?", comment: "") callMeButton.setTitle(NSLocalizedString("Call me", comment: ""), forState: .Normal) - verifyMobileNumberPromptLabelTopConstraint.constant = UIDevice.matchFrom(30, 50, 60, 60) - verifyCodeTextFieldTopConstraint.constant = UIDevice.matchFrom(30, 40, 50, 50) - callMeButtonTopConstraint.constant = UIDevice.matchFrom(10, 20, 40, 40) + verifyMobileNumberPromptLabelTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 50, 60, 60)) + verifyCodeTextFieldTopConstraint.constant = Ruler.match(.iPhoneHeights(30, 40, 50, 50)) + callMeButtonTopConstraint.constant = Ruler.match(.iPhoneHeights(10, 20, 40, 40)) } override func viewWillAppear(animated: Bool) { From c78cf7cf3865ad5aa4b77c8712882d53ddf65b62 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 22 Jul 2015 17:32:24 +0800 Subject: [PATCH 3/4] delete UIDevice+Yep --- Yep.xcodeproj/project.pbxproj | 4 -- Yep/Extensions/UIDevice+Yep.swift | 91 ------------------------------- 2 files changed, 95 deletions(-) delete mode 100644 Yep/Extensions/UIDevice+Yep.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 5d9a1cae..21ff1372 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -175,7 +175,6 @@ 508F8FDB1B0479E700461B0B /* SocialWorkInstagramViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508F8FDA1B0479E700461B0B /* SocialWorkInstagramViewController.swift */; }; 508F8FDE1B049ACF00461B0B /* InstagramMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508F8FDC1B049ACF00461B0B /* InstagramMediaCell.swift */; }; 508F8FDF1B049ACF00461B0B /* InstagramMediaCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 508F8FDD1B049ACF00461B0B /* InstagramMediaCell.xib */; }; - 508F8FE21B04B1F900461B0B /* UIDevice+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508F8FE11B04B1F900461B0B /* UIDevice+Yep.swift */; }; 5099B9C41AB9510D002F940B /* RankView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099B9C31AB9510D002F940B /* RankView.swift */; }; 5099B9C71AB99F7B002F940B /* RegisterPickAvatarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099B9C61AB99F7B002F940B /* RegisterPickAvatarViewController.swift */; }; 5099B9C91AB9A7CB002F940B /* CameraPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5099B9C81AB9A7CB002F940B /* CameraPreviewView.swift */; }; @@ -400,7 +399,6 @@ 508F8FDA1B0479E700461B0B /* SocialWorkInstagramViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocialWorkInstagramViewController.swift; path = ViewControllers/SocialWorks/SocialWorkInstagramViewController.swift; sourceTree = ""; }; 508F8FDC1B049ACF00461B0B /* InstagramMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InstagramMediaCell.swift; path = Views/Cells/InstagramMedia/InstagramMediaCell.swift; sourceTree = ""; }; 508F8FDD1B049ACF00461B0B /* InstagramMediaCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = InstagramMediaCell.xib; path = Views/Cells/InstagramMedia/InstagramMediaCell.xib; sourceTree = ""; }; - 508F8FE11B04B1F900461B0B /* UIDevice+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIDevice+Yep.swift"; path = "Extensions/UIDevice+Yep.swift"; sourceTree = ""; }; 5099B9C31AB9510D002F940B /* RankView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RankView.swift; path = Views/Rank/RankView.swift; sourceTree = ""; }; 5099B9C61AB99F7B002F940B /* RegisterPickAvatarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RegisterPickAvatarViewController.swift; path = ViewControllers/Register/RegisterPickAvatarViewController.swift; sourceTree = ""; }; 5099B9C81AB9A7CB002F940B /* CameraPreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CameraPreviewView.swift; path = Views/CameraPreview/CameraPreviewView.swift; sourceTree = ""; }; @@ -753,7 +751,6 @@ 0A3E605F1ACCA9C0003DC853 /* String+Yep.swift */, 50A9D44A1ACD37A8000B2599 /* NSFileManager+Yep.swift */, 50553F921ADBA50600F80B59 /* NSDate+Yep.swift */, - 508F8FE11B04B1F900461B0B /* UIDevice+Yep.swift */, 0AEB1CC51B0E742400178C9C /* Double+Yep.swift */, 503A54EC1B328ADB002077BD /* NSLocale+Yep.swift */, 501560D61B427FD6000933F0 /* Results+Yep.swift */, @@ -1700,7 +1697,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 508F8FE21B04B1F900461B0B /* UIDevice+Yep.swift in Sources */, 50894CFE1AEA5A78000981AF /* EditProfileViewController.swift in Sources */, 50CDBE421ACA9B4200459CE0 /* ChatRightImageCell.swift in Sources */, 5099B9C41AB9510D002F940B /* RankView.swift in Sources */, diff --git a/Yep/Extensions/UIDevice+Yep.swift b/Yep/Extensions/UIDevice+Yep.swift deleted file mode 100644 index 09efa4f4..00000000 --- a/Yep/Extensions/UIDevice+Yep.swift +++ /dev/null @@ -1,91 +0,0 @@ -// -// UIDevice+Yep.swift -// Yep -// -// Created by NIX on 15/5/14. -// Copyright (c) 2015年 Catch Inc. All rights reserved. -// - -import UIKit - -extension UIDevice { - - // 只考虑宽度的模型 - - enum ScreenWidthModel { - case Classic - case Bigger - case BiggerPlus - } - - static let screenWidthModel: ScreenWidthModel = { - - let screen = UIScreen.mainScreen() - let nativeWidth = screen.nativeBounds.size.width - - if nativeWidth == 320 * 2 { - return .Classic - - } else if nativeWidth == 375 * 2 { - return .Bigger - - } else if nativeWidth == 414 * 3 { - return .BiggerPlus - } - - return .Bigger // Default - }() - - class func matchWidthFrom(classic: CGFloat, _ bigger: CGFloat, _ biggerPlus: CGFloat) -> CGFloat { - switch screenWidthModel { - case .Classic: - return classic - case .Bigger: - return bigger - case .BiggerPlus: - return biggerPlus - } - } - - - // 整个屏幕的模型 - - enum ScreenModel { - case Inch35 - case Inch4 - case Bigger - case BiggerPlus - } - - static let screenModel: ScreenModel = { - - let screen = UIScreen.mainScreen() - let nativeWidth = screen.nativeBounds.size.width - - if nativeWidth == 320 * 2 { - let nativeHeight = screen.nativeBounds.size.height - return nativeHeight > (480 * 2) ? .Inch4 : .Inch35 - - } else if nativeWidth == 375 * 2 { - return .Bigger - - } else if nativeWidth == 414 * 3 { - return .BiggerPlus - } - - return .Bigger // Default - }() - - class func matchFrom(inch35: CGFloat, _ inch4: CGFloat, _ bigger: CGFloat, _ biggerPlus: CGFloat) -> CGFloat { - switch screenModel { - case .Inch35: - return inch35 - case .Inch4: - return inch4 - case .Bigger: - return bigger - case .BiggerPlus: - return biggerPlus - } - } -} From 494703c37fdc439a9ad8aa41f65af8e56b409801 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 22 Jul 2015 17:37:45 +0800 Subject: [PATCH 4/4] fix skillsFromUserSkillList (server dot return skillCategory, and relogin will lose skillCategory) --- Yep/Services/YepServiceSync.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Yep/Services/YepServiceSync.swift b/Yep/Services/YepServiceSync.swift index 800380e6..670e681e 100644 --- a/Yep/Services/YepServiceSync.swift +++ b/Yep/Services/YepServiceSync.swift @@ -20,18 +20,18 @@ func skillsFromUserSkillList(userSkillList: List) -> [Skill] { userSkills.append(userSkill) } - return userSkills.map({ userSkill -> Skill? in + return userSkills.map({ userSkill -> Skill in + + var skillCategory: SkillCategory? + if let category = userSkill.category { - let skillCategory = SkillCategory(id: category.skillCategoryID, name: category.name, localName: category.localName, skills: []) - - let skill = Skill(category: skillCategory, id: userSkill.skillID, name: userSkill.name, localName: userSkill.localName, coverURLString: userSkill.coverURLString) - - return skill + skillCategory = SkillCategory(id: category.skillCategoryID, name: category.name, localName: category.localName, skills: []) } - return nil + let skill = Skill(category: skillCategory, id: userSkill.skillID, name: userSkill.name, localName: userSkill.localName, coverURLString: userSkill.coverURLString) - }).filter({ $0 != nil }).map({ skill in skill! }) + return skill + }) } func userSkillsFromSkills(skills: [Skill], inRealm realm: Realm) -> [UserSkill] {