From 45c486f6da3fd8d9ccf45723cdeacee03bdcbb38 Mon Sep 17 00:00:00 2001 From: Hilen Date: Sat, 26 Nov 2016 21:56:29 +0800 Subject: [PATCH] Optimize --- README.md | 4 +- TSWeChat.xcodeproj/project.pbxproj | 20 -- .../Classes/Chat/Cells/TSChatBaseCell.swift | 2 +- .../Classes/Chat/Cells/TSChatImageCell.swift | 2 +- .../Classes/Chat/Cells/TSChatSystemCell.swift | 6 +- .../Classes/Chat/Cells/TSChatTextCell.swift | 4 +- .../Classes/Chat/Cells/TSChatTimeCell.swift | 6 +- .../Classes/Chat/Cells/TSChatVoiceCell.swift | 2 +- .../Chat/TSChatViewController+CellEnums.swift | 14 +- .../TSChatViewController+Interaction.swift | 2 +- .../Chat/TSChatViewController+Keyboard.swift | 8 +- .../Classes/Chat/TSChatViewController.swift | 10 +- .../Chat/Views/TSChatEmotionInputView.swift | 8 +- .../Chat/Views/TSChatShareMoreView.swift | 6 +- .../Discover/TSDiscoverViewController.swift | 5 +- TSWeChat/Classes/Me/TSMeViewController.swift | 9 +- .../Message/TSMessageViewController.swift | 6 +- .../Tabbar/TSTabbarViewController.swift | 8 +- TSWeChat/General/TSUIImageVIew+WeChat.swift | 2 +- TSWeChat/Helpers/CGRect+Extension.swift | 115 ------- TSWeChat/Helpers/Device.swift | 289 ------------------ TSWeChat/Helpers/UIImage+Orientation.swift | 74 ----- TSWeChat/Helpers/UILabel+Extension.swift | 44 --- TSWeChat/Helpers/UIScreen+Extension.swift | 50 --- 24 files changed, 51 insertions(+), 645 deletions(-) delete mode 100644 TSWeChat/Helpers/CGRect+Extension.swift delete mode 100644 TSWeChat/Helpers/Device.swift delete mode 100644 TSWeChat/Helpers/UIImage+Orientation.swift delete mode 100644 TSWeChat/Helpers/UILabel+Extension.swift delete mode 100644 TSWeChat/Helpers/UIScreen+Extension.swift diff --git a/README.md b/README.md index 3b47cf2..1d4c17f 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ TSWeChat - A [WeChat](https://itunes.apple.com/cn/app/wei/id414478124) alternative, written in Swift.       [中文说明](Chinese_README.md) ## Requirements -- [Cocoapods](https://github.com/CocoaPods/CocoaPods) 0.39.0 + +- [Cocoapods](https://github.com/CocoaPods/CocoaPods) 1.1.1 + - iOS 8.0+ / Mac OS X 10.9+ -- Xcode 7.3+ +- Xcode 8.1+ ## Features diff --git a/TSWeChat.xcodeproj/project.pbxproj b/TSWeChat.xcodeproj/project.pbxproj index 2351d63..754fe9f 100644 --- a/TSWeChat.xcodeproj/project.pbxproj +++ b/TSWeChat.xcodeproj/project.pbxproj @@ -49,12 +49,9 @@ AE8742911C7B3547003A435C /* TSContactTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87428F1C7B3547003A435C /* TSContactTableViewCell.swift */; }; AE8742921C7B3547003A435C /* TSContactTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = AE8742901C7B3547003A435C /* TSContactTableViewCell.xib */; }; AE8F49AC1C46A905009C1541 /* AboutApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F499D1C46A905009C1541 /* AboutApp.swift */; }; - AE8F49AD1C46A905009C1541 /* CGRect+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F499E1C46A905009C1541 /* CGRect+Extension.swift */; }; - AE8F49AE1C46A905009C1541 /* Device.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F499F1C46A905009C1541 /* Device.swift */; }; AE8F49B01C46A905009C1541 /* NSDictionary+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F49A11C46A905009C1541 /* NSDictionary+Extension.swift */; }; AE8F49B21C46A905009C1541 /* NSObject+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F49A31C46A905009C1541 /* NSObject+String.swift */; }; AE8F49B31C46A905009C1541 /* UIBarButtonItem+Block.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F49A41C46A905009C1541 /* UIBarButtonItem+Block.swift */; }; - AE8F49B51C46A905009C1541 /* UIScreen+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F49A61C46A905009C1541 /* UIScreen+Extension.swift */; }; AE8F49B61C46A905009C1541 /* UISearchBar+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F49A71C46A905009C1541 /* UISearchBar+Extension.swift */; }; AE8F49B91C46A905009C1541 /* UIView+Frame.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F49AA1C46A905009C1541 /* UIView+Frame.swift */; }; AE8F49BA1C46A905009C1541 /* UIViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8F49AB1C46A905009C1541 /* UIViewController+Extension.swift */; }; @@ -90,7 +87,6 @@ AEE69A5A1C7CB07C00C69224 /* Expression.plist in Resources */ = {isa = PBXBuildFile; fileRef = AEE69A591C7CB07C00C69224 /* Expression.plist */; }; AEE69B251C7CB2AF00C69224 /* Expression.bundle in Resources */ = {isa = PBXBuildFile; fileRef = AEE69B241C7CB2AF00C69224 /* Expression.bundle */; }; AEE69B621C81997500C69224 /* PHAsset+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69B5F1C81997500C69224 /* PHAsset+Extension.swift */; }; - AEE69B661C81999E00C69224 /* UIImage+Orientation.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69B651C81999E00C69224 /* UIImage+Orientation.swift */; }; AEE69BA01C81B58600C69224 /* TSChatBaseCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69B691C81B58600C69224 /* TSChatBaseCell.swift */; }; AEE69BA11C81B58600C69224 /* TSChatCellDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69B6A1C81B58600C69224 /* TSChatCellDelegate.swift */; }; AEE69BA21C81B58600C69224 /* TSChatImageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69B6B1C81B58600C69224 /* TSChatImageCell.swift */; }; @@ -138,7 +134,6 @@ AEE69C121C81B66100C69224 /* TSChatSubModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69C111C81B66100C69224 /* TSChatSubModel.swift */; }; AEE69C141C81B68500C69224 /* TSLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69C131C81B68500C69224 /* TSLogger.swift */; }; AEE69C161C81B6DD00C69224 /* TSChatModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69C151C81B6DD00C69224 /* TSChatModel.swift */; }; - AEE69C181C81B92700C69224 /* UILabel+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69C171C81B92700C69224 /* UILabel+Extension.swift */; }; AEE69C1B1C81B97F00C69224 /* TSWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69C1A1C81B97F00C69224 /* TSWebViewController.swift */; }; AEE69C1F1C81BF1F00C69224 /* TSConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE69C1E1C81BF1F00C69224 /* TSConfig.swift */; }; /* End PBXBuildFile section */ @@ -197,12 +192,9 @@ AE87428F1C7B3547003A435C /* TSContactTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSContactTableViewCell.swift; sourceTree = ""; }; AE8742901C7B3547003A435C /* TSContactTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TSContactTableViewCell.xib; sourceTree = ""; }; AE8F499D1C46A905009C1541 /* AboutApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutApp.swift; sourceTree = ""; }; - AE8F499E1C46A905009C1541 /* CGRect+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGRect+Extension.swift"; sourceTree = ""; }; - AE8F499F1C46A905009C1541 /* Device.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Device.swift; sourceTree = ""; }; AE8F49A11C46A905009C1541 /* NSDictionary+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSDictionary+Extension.swift"; sourceTree = ""; }; AE8F49A31C46A905009C1541 /* NSObject+String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSObject+String.swift"; sourceTree = ""; }; AE8F49A41C46A905009C1541 /* UIBarButtonItem+Block.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+Block.swift"; sourceTree = ""; }; - AE8F49A61C46A905009C1541 /* UIScreen+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIScreen+Extension.swift"; sourceTree = ""; }; AE8F49A71C46A905009C1541 /* UISearchBar+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UISearchBar+Extension.swift"; sourceTree = ""; }; AE8F49AA1C46A905009C1541 /* UIView+Frame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Frame.swift"; sourceTree = ""; }; AE8F49AB1C46A905009C1541 /* UIViewController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = ""; }; @@ -243,7 +235,6 @@ AEE69A591C7CB07C00C69224 /* Expression.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Expression.plist; sourceTree = ""; }; AEE69B241C7CB2AF00C69224 /* Expression.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Expression.bundle; sourceTree = ""; }; AEE69B5F1C81997500C69224 /* PHAsset+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "PHAsset+Extension.swift"; sourceTree = ""; }; - AEE69B651C81999E00C69224 /* UIImage+Orientation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Orientation.swift"; sourceTree = ""; }; AEE69B691C81B58600C69224 /* TSChatBaseCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSChatBaseCell.swift; sourceTree = ""; }; AEE69B6A1C81B58600C69224 /* TSChatCellDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSChatCellDelegate.swift; sourceTree = ""; }; AEE69B6B1C81B58600C69224 /* TSChatImageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSChatImageCell.swift; sourceTree = ""; }; @@ -291,7 +282,6 @@ AEE69C111C81B66100C69224 /* TSChatSubModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSChatSubModel.swift; sourceTree = ""; }; AEE69C131C81B68500C69224 /* TSLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSLogger.swift; sourceTree = ""; }; AEE69C151C81B6DD00C69224 /* TSChatModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSChatModel.swift; sourceTree = ""; }; - AEE69C171C81B92700C69224 /* UILabel+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UILabel+Extension.swift"; sourceTree = ""; }; AEE69C1A1C81B97F00C69224 /* TSWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSWebViewController.swift; sourceTree = ""; }; AEE69C1E1C81BF1F00C69224 /* TSConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TSConfig.swift; sourceTree = ""; }; EEDE4F6B7BF2C153C58B4744 /* Pods_TSWeChat.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TSWeChat.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -391,17 +381,12 @@ AE8F499C1C46A905009C1541 /* Helpers */ = { isa = PBXGroup; children = ( - AEE69C171C81B92700C69224 /* UILabel+Extension.swift */, AE8F499D1C46A905009C1541 /* AboutApp.swift */, - AE8F499E1C46A905009C1541 /* CGRect+Extension.swift */, - AE8F499F1C46A905009C1541 /* Device.swift */, AE8742781C7AE48A003A435C /* NSDate+Extension.swift */, AE8F49A11C46A905009C1541 /* NSDictionary+Extension.swift */, AE8F49A31C46A905009C1541 /* NSObject+String.swift */, AEE69B5F1C81997500C69224 /* PHAsset+Extension.swift */, AE8F49A41C46A905009C1541 /* UIBarButtonItem+Block.swift */, - AEE69B651C81999E00C69224 /* UIImage+Orientation.swift */, - AE8F49A61C46A905009C1541 /* UIScreen+Extension.swift */, AE8F49A71C46A905009C1541 /* UISearchBar+Extension.swift */, AE8F49AA1C46A905009C1541 /* UIView+Frame.swift */, AE8F49AB1C46A905009C1541 /* UIViewController+Extension.swift */, @@ -894,7 +879,6 @@ files = ( AE8F49BA1C46A905009C1541 /* UIViewController+Extension.swift in Sources */, AE8742751C7AE23E003A435C /* TSModel.swift in Sources */, - AE8F49AE1C46A905009C1541 /* Device.swift in Sources */, AEBEE5B01C8754BD00956B0C /* TSChatButton+UI.swift in Sources */, AEE69BB71C81B58600C69224 /* TSChatEmojiDictionary.swift in Sources */, AE8F49B91C46A905009C1541 /* UIView+Frame.swift in Sources */, @@ -944,7 +928,6 @@ AE8742611C7AE0F1003A435C /* TSProgressHUD.swift in Sources */, AEE69BB61C81B58600C69224 /* ImageFilesManager.swift in Sources */, AEE69C141C81B68500C69224 /* TSLogger.swift in Sources */, - AE8F49AD1C46A905009C1541 /* CGRect+Extension.swift in Sources */, AEE69BCE1C81B58600C69224 /* TSChatShareMoreCollectionViewCell.swift in Sources */, AE8742741C7AE23E003A435C /* TSMessageModel.swift in Sources */, AEE69BBB1C81B58600C69224 /* UITableView+ChatAdditions.swift in Sources */, @@ -962,9 +945,7 @@ AEE69BC51C81B58600C69224 /* TSChatViewController.swift in Sources */, AE040A9F1C990B4A003A764D /* TSLocationManager.swift in Sources */, AEE69BB81C81B58600C69224 /* TSChatTextParser.swift in Sources */, - AE8F49B51C46A905009C1541 /* UIScreen+Extension.swift in Sources */, AE92B7881C3FF7C900968A3A /* TSAppMacro.swift in Sources */, - AEE69C181C81B92700C69224 /* UILabel+Extension.swift in Sources */, AEE69BD31C81B58600C69224 /* TSChatVoiceIndicatorView.swift in Sources */, AEBEE5AE1C8754BD00956B0C /* TSChatSystemEdgeLabel.swift in Sources */, AEE69BB91C81B58600C69224 /* TSYYTextLinePositionModifier.swift in Sources */, @@ -977,7 +958,6 @@ AEE69C1F1C81BF1F00C69224 /* TSConfig.swift in Sources */, AEE69BAD1C81B58600C69224 /* AudioDelegate.swift in Sources */, AEBEE5A21C87087600956B0C /* TSResponseSerializer.swift in Sources */, - AEE69B661C81999E00C69224 /* UIImage+Orientation.swift in Sources */, AEE69BC91C81B58600C69224 /* TSChatEmotionCell.swift in Sources */, AE40FD241C5B644300CB7339 /* TSImageTextTableViewCell.swift in Sources */, AEE69C161C81B6DD00C69224 /* TSChatModel.swift in Sources */, diff --git a/TSWeChat/Classes/Chat/Cells/TSChatBaseCell.swift b/TSWeChat/Classes/Chat/Cells/TSChatBaseCell.swift index e5526e8..9177f97 100644 --- a/TSWeChat/Classes/Chat/Cells/TSChatBaseCell.swift +++ b/TSWeChat/Classes/Chat/Cells/TSChatBaseCell.swift @@ -76,7 +76,7 @@ class TSChatBaseCell: UITableViewCell { } if model.fromMe { self.nicknameLabel.height = 0 - self.avatarImageView.left = UIScreen.width - kChatAvatarMarginLeft - kChatAvatarWidth + self.avatarImageView.left = UIScreen.ts_width - kChatAvatarMarginLeft - kChatAvatarWidth } else { self.nicknameLabel.height = 0 self.avatarImageView.left = kChatAvatarMarginLeft diff --git a/TSWeChat/Classes/Chat/Cells/TSChatImageCell.swift b/TSWeChat/Classes/Chat/Cells/TSChatImageCell.swift index 12fea18..0fd70eb 100644 --- a/TSWeChat/Classes/Chat/Cells/TSChatImageCell.swift +++ b/TSWeChat/Classes/Chat/Cells/TSChatImageCell.swift @@ -74,7 +74,7 @@ class TSChatImageCell: TSChatBaseCell { if model.fromMe { //value = 屏幕宽 - 头像的边距10 - 头像宽 - 气泡距离头像的 gap 值 - 图片宽 - self.chatImageView.left = UIScreen.width - kChatAvatarMarginLeft - kChatAvatarWidth - kChatBubbleMaginLeft - self.chatImageView.width + self.chatImageView.left = UIScreen.ts_width - kChatAvatarMarginLeft - kChatAvatarWidth - kChatBubbleMaginLeft - self.chatImageView.width } else { //value = 距离屏幕左边的距离 self.chatImageView.left = kChatBubbleLeft diff --git a/TSWeChat/Classes/Chat/Cells/TSChatSystemCell.swift b/TSWeChat/Classes/Chat/Cells/TSChatSystemCell.swift index 373dd6c..5506c24 100644 --- a/TSWeChat/Classes/Chat/Cells/TSChatSystemCell.swift +++ b/TSWeChat/Classes/Chat/Cells/TSChatSystemCell.swift @@ -9,7 +9,7 @@ import UIKit private let kChatInfoFont: UIFont = UIFont.systemFont(ofSize: 13) -private let kChatInfoLabelMaxWdith : CGFloat = UIScreen.width - 40*2 +private let kChatInfoLabelMaxWdith : CGFloat = UIScreen.ts_width - 40*2 private let kChatInfoLabelPaddingLeft: CGFloat = 8 //左右分别留出 8 像素的留白 private let kChatInfoLabelPaddingTop: CGFloat = 4 //上下分别留出 4 像素的留白 private let kChatInfoLabelMarginTop: CGFloat = 3 //距离顶部 @@ -46,10 +46,10 @@ class TSChatSystemCell: UITableViewCell { guard let model = self.model else { return } - self.infomationLabel.setFrameWithString(model.messageContent!, width: kChatInfoLabelMaxWdith) + self.infomationLabel.ts_setFrameWithString(model.messageContent!, width: kChatInfoLabelMaxWdith) self.infomationLabel.width = self.infomationLabel.width + kChatInfoLabelPaddingLeft*2 //左右的留白 self.infomationLabel.height = self.infomationLabel.height + kChatInfoLabelPaddingTop*2 //上下的留白 - self.infomationLabel.left = (UIScreen.width - self.infomationLabel.width) / 2 + self.infomationLabel.left = (UIScreen.ts_width - self.infomationLabel.width) / 2 self.infomationLabel.top = kChatInfoLabelMarginTop } diff --git a/TSWeChat/Classes/Chat/Cells/TSChatTextCell.swift b/TSWeChat/Classes/Chat/Cells/TSChatTextCell.swift index f2c4d06..394afae 100644 --- a/TSWeChat/Classes/Chat/Cells/TSChatTextCell.swift +++ b/TSWeChat/Classes/Chat/Cells/TSChatTextCell.swift @@ -10,7 +10,7 @@ import UIKit import YYText let kChatTextLeft: CGFloat = 72 //消息在左边的时候, 文字距离屏幕左边的距离 -let kChatTextMaxWidth: CGFloat = UIScreen.width - kChatTextLeft - 82 //消息在右边, 70:文本离屏幕左的距离, 82:文本离屏幕右的距离 +let kChatTextMaxWidth: CGFloat = UIScreen.ts_width - kChatTextLeft - 82 //消息在右边, 70:文本离屏幕左的距离, 82:文本离屏幕右的距离 let kChatTextMarginTop: CGFloat = 12 //文字的顶部和气泡顶部相差 12 像素 let kChatTextMarginBottom: CGFloat = 11 //文字的底部和气泡底部相差 11 像素 let kChatTextMarginLeft: CGFloat = 17 //文字的左边 和气泡的左边相差 17 ,包括剪头部门 @@ -84,7 +84,7 @@ class TSChatTextCell: TSChatBaseCell { if model.fromMe { //value = 屏幕宽 - 头像的边距10 - 头像宽 - 气泡距离头像的 gap 值 - (文字宽 - 2倍的文字和气泡的左右距离 , 或者是最小的气泡图片距离) - self.bubbleImageView.left = UIScreen.width - kChatAvatarMarginLeft - kChatAvatarWidth - kChatBubbleMaginLeft - max(self.contentLabel.width + kChatBubbleWidthBuffer, kChatBubbleImageViewWidth) + self.bubbleImageView.left = UIScreen.ts_width - kChatAvatarMarginLeft - kChatAvatarWidth - kChatBubbleMaginLeft - max(self.contentLabel.width + kChatBubbleWidthBuffer, kChatBubbleImageViewWidth) } else { //value = 距离屏幕左边的距离 self.bubbleImageView.left = kChatBubbleLeft diff --git a/TSWeChat/Classes/Chat/Cells/TSChatTimeCell.swift b/TSWeChat/Classes/Chat/Cells/TSChatTimeCell.swift index 8f85b31..5e8f3ad 100644 --- a/TSWeChat/Classes/Chat/Cells/TSChatTimeCell.swift +++ b/TSWeChat/Classes/Chat/Cells/TSChatTimeCell.swift @@ -8,7 +8,7 @@ import UIKit -private let kChatTimeLabelMaxWdith : CGFloat = UIScreen.width - 30*2 +private let kChatTimeLabelMaxWdith : CGFloat = UIScreen.ts_width - 30*2 private let kChatTimeLabelPaddingLeft: CGFloat = 6 //左右分别留出 6 像素的留白 private let kChatTimeLabelPaddingTop: CGFloat = 3 //上下分别留出 3 像素的留白 private let kChatTimeLabelMarginTop: CGFloat = 10 //顶部 10 px @@ -38,9 +38,9 @@ class TSChatTimeCell: UITableViewCell { guard let message = self.model?.messageContent else { return } - self.timeLabel.setFrameWithString(message, width: kChatTimeLabelMaxWdith) + self.timeLabel.ts_setFrameWithString(message, width: kChatTimeLabelMaxWdith) self.timeLabel.width = self.timeLabel.width + kChatTimeLabelPaddingLeft*2 //左右的留白 - self.timeLabel.left = (UIScreen.width - self.timeLabel.width) / 2 + self.timeLabel.left = (UIScreen.ts_width - self.timeLabel.width) / 2 self.timeLabel.height = self.timeLabel.height + kChatTimeLabelPaddingTop*2 self.timeLabel.top = kChatTimeLabelMarginTop } diff --git a/TSWeChat/Classes/Chat/Cells/TSChatVoiceCell.swift b/TSWeChat/Classes/Chat/Cells/TSChatVoiceCell.swift index 445ebf4..c55b232 100644 --- a/TSWeChat/Classes/Chat/Cells/TSChatVoiceCell.swift +++ b/TSWeChat/Classes/Chat/Cells/TSChatVoiceCell.swift @@ -103,7 +103,7 @@ class TSChatVoiceCell: TSChatBaseCell { if model.fromMe { //value = 屏幕宽 - 头像的边距10 - 头像宽 - 气泡距离头像的 gap 值 - 文字宽 - 2倍的文字和气泡的左右距离 - self.listenVoiceButton.left = UIScreen.width - kChatAvatarMarginLeft - kChatAvatarWidth - kChatBubbleMaginLeft - self.listenVoiceButton.width + self.listenVoiceButton.left = UIScreen.ts_width - kChatAvatarMarginLeft - kChatAvatarWidth - kChatBubbleMaginLeft - self.listenVoiceButton.width //value = 声音的左 - 秒数文字的宽 - 间隔值 self.durationLabel.left = self.listenVoiceButton.left - self.durationLabel.width self.durationLabel.textAlignment = .right diff --git a/TSWeChat/Classes/Chat/TSChatViewController+CellEnums.swift b/TSWeChat/Classes/Chat/TSChatViewController+CellEnums.swift index 3f98eb7..c5a8922 100644 --- a/TSWeChat/Classes/Chat/TSChatViewController+CellEnums.swift +++ b/TSWeChat/Classes/Chat/TSChatViewController+CellEnums.swift @@ -31,36 +31,36 @@ extension MessageContentType { func chatCell(_ tableView: UITableView, indexPath: IndexPath, model: ChatModel, viewController: TSChatViewController) -> UITableViewCell? { switch self { case .Text : - let cell = tableView.dequeueReusableCell(withIdentifier: TSChatTextCell.identifier, for: indexPath) as! TSChatTextCell + let cell: TSChatTextCell = tableView.ts_dequeueReusableCell(TSChatTextCell.self) cell.delegate = viewController cell.setCellContent(model) return cell case .Image : - let cell = tableView.dequeueReusableCell(withIdentifier: TSChatImageCell.identifier, for: indexPath) as! TSChatImageCell + let cell: TSChatImageCell = tableView.ts_dequeueReusableCell(TSChatImageCell.self) cell.delegate = viewController cell.setCellContent(model) return cell case .Voice: - let cell = tableView.dequeueReusableCell(withIdentifier: TSChatVoiceCell.identifier, for: indexPath) as! TSChatVoiceCell + let cell: TSChatVoiceCell = tableView.ts_dequeueReusableCell(TSChatVoiceCell.self) cell.delegate = viewController cell.setCellContent(model) return cell case .System: - let cell = tableView.dequeueReusableCell(withIdentifier: TSChatSystemCell.identifier, for: indexPath) as! TSChatSystemCell + let cell: TSChatSystemCell = tableView.ts_dequeueReusableCell(TSChatSystemCell.self) cell.setCellContent(model) return cell - + case .File: - let cell = tableView.dequeueReusableCell(withIdentifier: TSChatVoiceCell.identifier, for: indexPath) as! TSChatVoiceCell + let cell: TSChatVoiceCell = tableView.ts_dequeueReusableCell(TSChatVoiceCell.self) cell.delegate = viewController cell.setCellContent(model) return cell case .Time : - let cell = tableView.dequeueReusableCell(withIdentifier: TSChatTimeCell.identifier, for: indexPath) as! TSChatTimeCell + let cell: TSChatTimeCell = tableView.ts_dequeueReusableCell(TSChatTimeCell.self) cell.setCellContent(model) return cell } diff --git a/TSWeChat/Classes/Chat/TSChatViewController+Interaction.swift b/TSWeChat/Classes/Chat/TSChatViewController+Interaction.swift index 96eaff5..93b57c7 100644 --- a/TSWeChat/Classes/Chat/TSChatViewController+Interaction.swift +++ b/TSWeChat/Classes/Chat/TSChatViewController+Interaction.swift @@ -65,7 +65,7 @@ extension TSChatViewController: ChatShareMoreViewDelegate { //处理图片,并且发送图片消息 func resizeAndSendImage(_ theImage: UIImage) { - let originalImage = UIImage.fixImageOrientation(theImage) + let originalImage = UIImage.ts_fixImageOrientation(theImage) let storeKey = "send_image"+String(format: "%f", Date.milliseconds) let thumbSize = ChatConfig.getThumbImageSize(originalImage.size) diff --git a/TSWeChat/Classes/Chat/TSChatViewController+Keyboard.swift b/TSWeChat/Classes/Chat/TSChatViewController+Keyboard.swift index 8a9b220..ccf3ee8 100644 --- a/TSWeChat/Classes/Chat/TSChatViewController+Keyboard.swift +++ b/TSWeChat/Classes/Chat/TSChatViewController+Keyboard.swift @@ -200,7 +200,7 @@ extension TSChatViewController: TSChatActionBarViewDelegate { 调起表情键盘 */ func chatActionBarShowEmotionKeyboard() { - let heightOffset = self.emotionInputView.height + let heightOffset = self.emotionInputView.ts_height self.listTableView.stopScrolling() self.actionBarPaddingBottomConstranit?.update(offset: -heightOffset) @@ -215,7 +215,7 @@ extension TSChatViewController: TSChatActionBarViewDelegate { } //分享键盘隐藏 self.shareMoreView.snp.updateConstraints { make in - make.top.equalTo(self.chatActionBarView.snp.bottom).offset(self.view.height) + make.top.equalTo(self.chatActionBarView.snp.bottom).offset(self.view.ts_height) } self.view.layoutIfNeeded() self.listTableView.scrollBottomToLastRow() @@ -228,11 +228,11 @@ extension TSChatViewController: TSChatActionBarViewDelegate { 调起分享键盘 */ func chatActionBarShowShareKeyboard() { - let heightOffset = self.shareMoreView.height + let heightOffset = self.shareMoreView.ts_height self.listTableView.stopScrolling() self.actionBarPaddingBottomConstranit?.update(offset: -heightOffset) - self.shareMoreView.top = self.view.height + self.shareMoreView.ts_top = self.view.ts_height self.view.bringSubview(toFront: self.shareMoreView) UIView.animate( withDuration: 0.25, diff --git a/TSWeChat/Classes/Chat/TSChatViewController.swift b/TSWeChat/Classes/Chat/TSChatViewController.swift index f43e90a..182e4a9 100644 --- a/TSWeChat/Classes/Chat/TSChatViewController.swift +++ b/TSWeChat/Classes/Chat/TSChatViewController.swift @@ -54,11 +54,11 @@ final class TSChatViewController: UIViewController { self.navigationController!.interactivePopGestureRecognizer!.isEnabled = true //TableView init - self.listTableView.register(TSChatTextCell.ts_Nib(), forCellReuseIdentifier: TSChatTextCell.identifier) - self.listTableView.register(TSChatImageCell.ts_Nib(), forCellReuseIdentifier: TSChatImageCell.identifier) - self.listTableView.register(TSChatVoiceCell.ts_Nib(), forCellReuseIdentifier: TSChatVoiceCell.identifier) - self.listTableView.register(TSChatSystemCell.ts_Nib(), forCellReuseIdentifier: TSChatSystemCell.identifier) - self.listTableView.register(TSChatTimeCell.ts_Nib(), forCellReuseIdentifier: TSChatTimeCell.identifier) + self.listTableView.ts_registerCellNib(TSChatTextCell.self) + self.listTableView.ts_registerCellNib(TSChatImageCell.self) + self.listTableView.ts_registerCellNib(TSChatVoiceCell.self) + self.listTableView.ts_registerCellNib(TSChatSystemCell.self) + self.listTableView.ts_registerCellNib(TSChatTimeCell.self) self.listTableView.tableFooterView = UIView() self.listTableView.tableHeaderView = self.refreshView diff --git a/TSWeChat/Classes/Chat/Views/TSChatEmotionInputView.swift b/TSWeChat/Classes/Chat/Views/TSChatEmotionInputView.swift index 1670523..b92c99e 100644 --- a/TSWeChat/Classes/Chat/Views/TSChatEmotionInputView.swift +++ b/TSWeChat/Classes/Chat/Views/TSChatEmotionInputView.swift @@ -41,10 +41,10 @@ class TSChatEmotionInputView: UIView { self.isUserInteractionEnabled = true //calculate width and height - let itemWidth = (UIScreen.width - 10 * 2) / kNumberOfOneRow - let padding = (UIScreen.width - kNumberOfOneRow * itemWidth) / 2.0 + let itemWidth = (UIScreen.ts_width - 10 * 2) / kNumberOfOneRow + let padding = (UIScreen.ts_width - kNumberOfOneRow * itemWidth) / 2.0 let paddingLeft = padding - let paddingRight = UIScreen.width - paddingLeft - itemWidth * kNumberOfOneRow + let paddingRight = UIScreen.ts_width - paddingLeft - itemWidth * kNumberOfOneRow //init FlowLayout let layout = UICollectionViewFlowLayout() @@ -133,7 +133,7 @@ extension TSChatEmotionInputView: UICollectionViewDataSource { // MARK: - @protocol UIScrollViewDelegate extension TSChatEmotionInputView: UIScrollViewDelegate { func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { - let pageWidth: CGFloat = self.listCollectionView.frame.sizeWidth + let pageWidth: CGFloat = self.listCollectionView.ts_width self.emotionPageControl.currentPage = Int(self.listCollectionView.contentOffset.x / pageWidth) } diff --git a/TSWeChat/Classes/Chat/Views/TSChatShareMoreView.swift b/TSWeChat/Classes/Chat/Views/TSChatShareMoreView.swift index eb56bed..2d36ae4 100644 --- a/TSWeChat/Classes/Chat/Views/TSChatShareMoreView.swift +++ b/TSWeChat/Classes/Chat/Views/TSChatShareMoreView.swift @@ -70,7 +70,7 @@ class TSChatShareMoreView: UIView { kLeftRightPadding ) //Calculate the UICollectionViewCell size - let itemSizeWidth = (UIScreen.width - kLeftRightPadding*2 - layout.minimumLineSpacing*(kItemCountOfRow - 1)) / kItemCountOfRow + let itemSizeWidth = (UIScreen.ts_width - kLeftRightPadding*2 - layout.minimumLineSpacing*(kItemCountOfRow - 1)) / kItemCountOfRow let itemSizeHeight = (self.collectionViewHeightConstraint.constant - kTopBottomPadding*2)/2 layout.itemSize = CGSize(width: itemSizeWidth, height: itemSizeHeight) @@ -91,7 +91,7 @@ class TSChatShareMoreView: UIView { override func layoutSubviews() { super.layoutSubviews() //Fix the width - self.listCollectionView.width = UIScreen.width + self.listCollectionView.width = UIScreen.ts_width } } @@ -150,7 +150,7 @@ extension TSChatShareMoreView: UICollectionViewDataSource { // MARK: - @protocol UIScrollViewDelegate extension TSChatShareMoreView: UIScrollViewDelegate { func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { - let pageWidth: CGFloat = self.listCollectionView.frame.sizeWidth + let pageWidth: CGFloat = self.listCollectionView.ts_width self.pageControl.currentPage = Int(self.listCollectionView.contentOffset.x / pageWidth) } } diff --git a/TSWeChat/Classes/Discover/TSDiscoverViewController.swift b/TSWeChat/Classes/Discover/TSDiscoverViewController.swift index fa43d99..5415536 100644 --- a/TSWeChat/Classes/Discover/TSDiscoverViewController.swift +++ b/TSWeChat/Classes/Discover/TSDiscoverViewController.swift @@ -31,8 +31,7 @@ class TSDiscoverViewController: UIViewController { super.viewDidLoad() self.title = "发现" self.view.backgroundColor = UIColor.viewBackgroundColor - - self.listTableView.register(TSImageTextTableViewCell.ts_Nib(), forCellReuseIdentifier: TSImageTextTableViewCell.identifier) + self.listTableView.ts_registerCellNib(TSImageTextTableViewCell.self) self.listTableView.estimatedRowHeight = 44 self.listTableView.tableFooterView = UIView() @@ -96,7 +95,7 @@ extension TSDiscoverViewController: UITableViewDataSource { } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: TSImageTextTableViewCell.identifier, for: indexPath) as! TSImageTextTableViewCell + let cell :TSImageTextTableViewCell = tableView.ts_dequeueReusableCell(TSImageTextTableViewCell.self) let item = self.itemDataSouce[indexPath.section][indexPath.row] cell.iconImageView.image = item.iconImage cell.titleLabel.text = item.name diff --git a/TSWeChat/Classes/Me/TSMeViewController.swift b/TSWeChat/Classes/Me/TSMeViewController.swift index 099a194..3ad9bf9 100644 --- a/TSWeChat/Classes/Me/TSMeViewController.swift +++ b/TSWeChat/Classes/Me/TSMeViewController.swift @@ -33,9 +33,8 @@ class TSMeViewController: UIViewController { super.viewDidLoad() self.title = "我" self.view.backgroundColor = UIColor.viewBackgroundColor - - self.listTableView.register(TSMeAvatarTableViewCell.ts_Nib(), forCellReuseIdentifier: TSMeAvatarTableViewCell.identifier) - self.listTableView.register(TSImageTextTableViewCell.ts_Nib(), forCellReuseIdentifier: TSImageTextTableViewCell.identifier) + self.listTableView.ts_registerCellNib(TSMeAvatarTableViewCell.self) + self.listTableView.ts_registerCellNib(TSImageTextTableViewCell.self) self.listTableView.tableFooterView = UIView() } @@ -103,10 +102,10 @@ extension TSMeViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.section == 0 { - let cell = tableView.dequeueReusableCell(withIdentifier: TSMeAvatarTableViewCell.identifier, for: indexPath) as! TSMeAvatarTableViewCell + let cell:TSMeAvatarTableViewCell = tableView.ts_dequeueReusableCell(TSMeAvatarTableViewCell.self) return cell } else { - let cell = tableView.dequeueReusableCell(withIdentifier: TSImageTextTableViewCell.identifier, for: indexPath) as! TSImageTextTableViewCell + let cell:TSImageTextTableViewCell = tableView.ts_dequeueReusableCell(TSImageTextTableViewCell.self) let item = self.itemDataSouce[indexPath.section][indexPath.row] cell.iconImageView.image = item.iconImage cell.titleLabel.text = item.name diff --git a/TSWeChat/Classes/Message/TSMessageViewController.swift b/TSWeChat/Classes/Message/TSMessageViewController.swift index 058da61..1fb6f8c 100644 --- a/TSWeChat/Classes/Message/TSMessageViewController.swift +++ b/TSWeChat/Classes/Message/TSMessageViewController.swift @@ -32,7 +32,7 @@ class TSMessageViewController: UIViewController { } //Init listTableView - self.listTableView.register(TSMessageTableViewCell.ts_Nib(), forCellReuseIdentifier: TSMessageTableViewCell.identifier) + self.listTableView.ts_registerCellNib(TSMessageTableViewCell.self) self.listTableView.estimatedRowHeight = 65 self.listTableView.tableFooterView = UIView() @@ -76,7 +76,7 @@ class TSMessageViewController: UIViewController { extension TSMessageViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) - let viewController = TSChatViewController.initFromNib() as! TSChatViewController + let viewController = TSChatViewController.ts_initFromNib() as! TSChatViewController viewController.messageModel = self.itemDataSouce[indexPath.row] self.ts_pushAndHideTabbar(viewController) } @@ -97,7 +97,7 @@ extension TSMessageViewController: UITableViewDataSource { } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: TSMessageTableViewCell.identifier, for: indexPath) as! TSMessageTableViewCell + let cell: TSMessageTableViewCell = tableView.ts_dequeueReusableCell(TSMessageTableViewCell.self) cell.setCellContnet(self.itemDataSouce[indexPath.row]) return cell } diff --git a/TSWeChat/Classes/Tabbar/TSTabbarViewController.swift b/TSWeChat/Classes/Tabbar/TSTabbarViewController.swift index 86aae12..bbf4c02 100644 --- a/TSWeChat/Classes/Tabbar/TSTabbarViewController.swift +++ b/TSWeChat/Classes/Tabbar/TSTabbarViewController.swift @@ -34,10 +34,10 @@ class TSTabbarViewController: UITabBarController { ] let viewControllerArray = [ - TSMessageViewController.initFromNib(), //消息 - TSContactsViewController.initFromNib(), //联系人 - TSDiscoverViewController.initFromNib(), //发现 - TSMeViewController.initFromNib() //我 + TSMessageViewController.ts_initFromNib(), //消息 + TSContactsViewController.ts_initFromNib(), //联系人 + TSDiscoverViewController.ts_initFromNib(), //发现 + TSMeViewController.ts_initFromNib() //我 ] let navigationVCArray = NSMutableArray() diff --git a/TSWeChat/General/TSUIImageVIew+WeChat.swift b/TSWeChat/General/TSUIImageVIew+WeChat.swift index 0be0005..c4ec559 100644 --- a/TSWeChat/General/TSUIImageVIew+WeChat.swift +++ b/TSWeChat/General/TSUIImageVIew+WeChat.swift @@ -31,7 +31,7 @@ public extension UIImageView { self.ts_setRoundImageWithURLString( URLString, placeholderImage: placeholder, - cornerRadiusRatio: self.width / 2 + cornerRadiusRatio: self.ts_width / 2 ) } diff --git a/TSWeChat/Helpers/CGRect+Extension.swift b/TSWeChat/Helpers/CGRect+Extension.swift deleted file mode 100644 index 52c65e3..0000000 --- a/TSWeChat/Helpers/CGRect+Extension.swift +++ /dev/null @@ -1,115 +0,0 @@ -// -// File.swift -// TSWeChat -// -// Created by Hilen on 11/5/15. -// Copyright © 2015 Hilen. All rights reserved. -// - -import Foundation - -public extension CGRect { - var originX: CGFloat { - get { - return self.origin.x - } - set { - self = CGRect(x: newValue, y: self.minY, width: self.sizeWidth, height: self.sizeHeight) - } - } - - var originY: CGFloat { - get { - return self.origin.y - } - set { - self = CGRect(x: self.originX, y: newValue, width: self.sizeWidth, height: self.sizeHeight) - } - } - - var sizeWidth: CGFloat { - get { - return self.size.width - } - set { - self = CGRect(x: self.originX, y: self.minY, width: newValue, height: self.sizeHeight) - } - } - - var sizeHeight: CGFloat { - get { - return self.size.height - } - set { - self = CGRect(x: self.originX, y: self.minY, width: self.sizeWidth, height: newValue) - } - } - - var top: CGFloat { - get { - return self.origin.y - } - set { - originY = newValue - } - } - - var bottom: CGFloat { - get { - return self.origin.y + self.size.height - } - set { - self = CGRect(x: originX, y: newValue - sizeHeight, width: sizeWidth, height: sizeHeight) - } - } - - var left: CGFloat { - get { - return self.origin.x - } - set { - self.originX = newValue - } - } - - var right: CGFloat { - get { - return originX + sizeWidth - } - set { - self = CGRect(x: newValue - sizeWidth, y: originY, width: sizeWidth, height: sizeHeight) - } - } - - - var midX: CGFloat { - get { - return self.originX + self.sizeWidth / 2 - } - set { - self = CGRect(x: newValue - sizeWidth / 2, y: originY, width: sizeWidth, height: sizeHeight) - } - } - - var midY: CGFloat { - get { - return self.originY + self.sizeHeight / 2 - } - set { - self = CGRect(x: originX, y: newValue - height / 2, width: sizeWidth, height: sizeHeight) - } - } - - - var center: CGPoint { - get { - return CGPoint(x: self.midX, y: self.midY) - } - set { - self = CGRect(x: newValue.x - sizeWidth / 2, y: newValue.y - sizeHeight / 2, width: sizeWidth, height: sizeHeight) - } - } -} - - - diff --git a/TSWeChat/Helpers/Device.swift b/TSWeChat/Helpers/Device.swift deleted file mode 100644 index c91e192..0000000 --- a/TSWeChat/Helpers/Device.swift +++ /dev/null @@ -1,289 +0,0 @@ -// -// Device.swift -// TSWeChat -// -// Created by Hilen on 12/22/15. -// Copyright © 2015 Hilen. All rights reserved. -// - -//https://gist.github.com/imkevinxu/2bb1197552b095ab25c8 - -import Foundation - -struct Device { - - // MARK: - Singletons - - static var TheCurrentDevice: UIDevice { - struct Singleton { - static let device = UIDevice.current - } - return Singleton.device - } - - static var TheCurrentDeviceVersion: Float { - struct Singleton { - static let version = (UIDevice.current.systemVersion as NSString).floatValue - } - return Singleton.version - } - - static var TheCurrentDeviceHeight: CGFloat { - struct Singleton { - static let height = UIScreen.main.bounds.size.height - } - return Singleton.height - } - - // MARK: - Device Idiom Checks - - static var PHONE_OR_PAD: String { - if isPhone() { - return "iPhone" - } else if isPad() { - return "iPad" - } - return "Not iPhone nor iPad" - } - - static var DEBUG_OR_RELEASE: String { - #if DEBUG - return "Debug" - #else - return "Release" - #endif - } - - static var SIMULATOR_OR_DEVICE: String { - #if (arch(i386) || arch(x86_64)) && os(iOS) - return "Simulator" - #else - return "Device" - #endif - } - - static func isPhone() -> Bool { - return TheCurrentDevice.userInterfaceIdiom == .phone - } - - static func isPad() -> Bool { - return TheCurrentDevice.userInterfaceIdiom == .pad - } - - static func isDebug() -> Bool { - return DEBUG_OR_RELEASE == "Debug" - } - - static func isRelease() -> Bool { - return DEBUG_OR_RELEASE == "Release" - } - - static func isSimulator() -> Bool { - return SIMULATOR_OR_DEVICE == "Simulator" - } - - static func isDevice() -> Bool { - return SIMULATOR_OR_DEVICE == "Device" - } - - // MARK: - Device Version Checks - - enum Versions: Float { - case five = 5.0 - case six = 6.0 - case seven = 7.0 - case eight = 8.0 - case nine = 9.0 - } - - static func isVersion(_ version: Versions) -> Bool { - return TheCurrentDeviceVersion >= version.rawValue && TheCurrentDeviceVersion < (version.rawValue + 1.0) - } - - static func isVersionOrLater(_ version: Versions) -> Bool { - return TheCurrentDeviceVersion >= version.rawValue - } - - static func isVersionOrEarlier(_ version: Versions) -> Bool { - return TheCurrentDeviceVersion < (version.rawValue + 1.0) - } - - static var CURRENT_VERSION: String { - return "\(TheCurrentDeviceVersion)" - } - - // MARK: iOS 5 Checks - - static func IS_OS_5() -> Bool { - return isVersion(.five) - } - - static func IS_OS_5_OR_LATER() -> Bool { - return isVersionOrLater(.five) - } - - static func IS_OS_5_OR_EARLIER() -> Bool { - return isVersionOrEarlier(.five) - } - - // MARK: iOS 6 Checks - - static func IS_OS_6() -> Bool { - return isVersion(.six) - } - - static func IS_OS_6_OR_LATER() -> Bool { - return isVersionOrLater(.six) - } - - static func IS_OS_6_OR_EARLIER() -> Bool { - return isVersionOrEarlier(.six) - } - - // MARK: iOS 7 Checks - - static func IS_OS_7() -> Bool { - return isVersion(.seven) - } - - static func IS_OS_7_OR_LATER() -> Bool { - return isVersionOrLater(.seven) - } - - static func IS_OS_7_OR_EARLIER() -> Bool { - return isVersionOrEarlier(.seven) - } - - // MARK: iOS 8 Checks - - static func IS_OS_8() -> Bool { - return isVersion(.eight) - } - - static func IS_OS_8_OR_LATER() -> Bool { - return isVersionOrLater(.eight) - } - - static func IS_OS_8_OR_EARLIER() -> Bool { - return isVersionOrEarlier(.eight) - } - - // MARK: iOS 9 Checks - - static func IS_OS_9() -> Bool { - return isVersion(.nine) - } - - static func IS_OS_9_OR_LATER() -> Bool { - return isVersionOrLater(.nine) - } - - static func IS_OS_9_OR_EARLIER() -> Bool { - return isVersionOrEarlier(.nine) - } - - // MARK: - Device Size Checks - - enum Heights: CGFloat { - case inches_3_5 = 480 - case inches_4 = 568 - case inches_4_7 = 667 - case inches_5_5 = 736 - } - - static func isSize(_ height: Heights) -> Bool { - return TheCurrentDeviceHeight == height.rawValue - } - - static func isSizeOrLarger(_ height: Heights) -> Bool { - return TheCurrentDeviceHeight >= height.rawValue - } - - static func isSizeOrSmaller(_ height: Heights) -> Bool { - return TheCurrentDeviceHeight <= height.rawValue - } - - static var CURRENT_SIZE: String { - if IS_3_5_INCHES() { - return "3.5 Inches" - } else if IS_4_INCHES() { - return "4 Inches" - } else if IS_4_7_INCHES() { - return "4.7 Inches" - } else if IS_5_5_INCHES() { - return "5.5 Inches" - } - return "\(TheCurrentDeviceHeight) Points" - } - - // MARK: Retina Check - - static func IS_RETINA() -> Bool { - return UIScreen.main.responds(to: #selector(NSDecimalNumberBehaviors.scale)) - } - - // MARK: 3.5 Inch Checks - - static func IS_3_5_INCHES() -> Bool { - return isPhone() && isSize(.inches_3_5) - } - - static func IS_3_5_INCHES_OR_LARGER() -> Bool { - return isPhone() && isSizeOrLarger(.inches_3_5) - } - - static func IS_3_5_INCHES_OR_SMALLER() -> Bool { - return isPhone() && isSizeOrSmaller(.inches_3_5) - } - - // MARK: 4 Inch Checks - - static func IS_4_INCHES() -> Bool { - return isPhone() && isSize(.inches_4) - } - - static func IS_4_INCHES_OR_LARGER() -> Bool { - return isPhone() && isSizeOrLarger(.inches_4) - } - - static func IS_4_INCHES_OR_SMALLER() -> Bool { - return isPhone() && isSizeOrSmaller(.inches_4) - } - - // MARK: 4.7 Inch Checks - - static func IS_4_7_INCHES() -> Bool { - return isPhone() && isSize(.inches_4_7) - } - - static func IS_4_7_INCHES_OR_LARGER() -> Bool { - return isPhone() && isSizeOrLarger(.inches_4_7) - } - - static func IS_4_7_INCHES_OR_SMALLER() -> Bool { - return isPhone() && isSizeOrLarger(.inches_4_7) - } - - // MARK: 5.5 Inch Checks - - static func IS_5_5_INCHES() -> Bool { - return isPhone() && isSize(.inches_5_5) - } - - static func IS_5_5_INCHES_OR_LARGER() -> Bool { - return isPhone() && isSizeOrLarger(.inches_5_5) - } - - static func IS_5_5_INCHES_OR_SMALLER() -> Bool { - return isPhone() && isSizeOrLarger(.inches_5_5) - } - - // MARK: - International Checks - - static var CURRENT_REGION: String { - return (Locale.current as NSLocale).object(forKey: NSLocale.Key.countryCode) as! String - } -} - - - diff --git a/TSWeChat/Helpers/UIImage+Orientation.swift b/TSWeChat/Helpers/UIImage+Orientation.swift deleted file mode 100644 index 3f157eb..0000000 --- a/TSWeChat/Helpers/UIImage+Orientation.swift +++ /dev/null @@ -1,74 +0,0 @@ -// -// UIImage+Orientation.swift -// TSWeChat -// -// Created by Hilen on 2/17/16. -// Copyright © 2016 Hilen. All rights reserved. -// - -import Foundation - -//https://github.com/cosnovae/fixUIImageOrientation/blob/master/fixImageOrientation.swift - -public extension UIImage { - class func fixImageOrientation(_ src:UIImage) -> UIImage { - - if src.imageOrientation == UIImageOrientation.up { - return src - } - - var transform: CGAffineTransform = CGAffineTransform.identity - - switch src.imageOrientation { - case UIImageOrientation.down, UIImageOrientation.downMirrored: - transform = transform.translatedBy(x: src.size.width, y: src.size.height) - transform = transform.rotated(by: CGFloat(M_PI)) - break - case UIImageOrientation.left, UIImageOrientation.leftMirrored: - transform = transform.translatedBy(x: src.size.width, y: 0) - transform = transform.rotated(by: CGFloat(M_PI_2)) - break - case UIImageOrientation.right, UIImageOrientation.rightMirrored: - transform = transform.translatedBy(x: 0, y: src.size.height) - transform = transform.rotated(by: CGFloat(-M_PI_2)) - break - case UIImageOrientation.up, UIImageOrientation.upMirrored: - break - } - - switch src.imageOrientation { - case UIImageOrientation.upMirrored, UIImageOrientation.downMirrored: - transform.translatedBy(x: src.size.width, y: 0) - transform.scaledBy(x: -1, y: 1) - break - case UIImageOrientation.leftMirrored, UIImageOrientation.rightMirrored: - transform.translatedBy(x: src.size.height, y: 0) - transform.scaledBy(x: -1, y: 1) - case UIImageOrientation.up, UIImageOrientation.down, UIImageOrientation.left, UIImageOrientation.right: - break - } - - let ctx:CGContext = CGContext(data: nil, width: Int(src.size.width), height: Int(src.size.height), bitsPerComponent: (src.cgImage)!.bitsPerComponent, bytesPerRow: 0, space: (src.cgImage)!.colorSpace!, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)! - - ctx.concatenate(transform) - - switch src.imageOrientation { - case UIImageOrientation.left, UIImageOrientation.leftMirrored, UIImageOrientation.right, UIImageOrientation.rightMirrored: - ctx.draw(src.cgImage!, in: CGRect(x: 0, y: 0, width: src.size.height, height: src.size.width)) - break - default: - ctx.draw(src.cgImage!, in: CGRect(x: 0, y: 0, width: src.size.width, height: src.size.height)) - break - } - - let cgimage:CGImage = ctx.makeImage()! - let image:UIImage = UIImage(cgImage: cgimage) - - return image - } -} - - - - - diff --git a/TSWeChat/Helpers/UILabel+Extension.swift b/TSWeChat/Helpers/UILabel+Extension.swift deleted file mode 100644 index c8f6043..0000000 --- a/TSWeChat/Helpers/UILabel+Extension.swift +++ /dev/null @@ -1,44 +0,0 @@ -// -// UILabel+Extension.swift -// TSWeChat -// -// Created by Hilen on 1/19/16. -// Copyright © 2016 Hilen. All rights reserved. -// - -import Foundation - -extension UILabel { - func contentSize() -> CGSize { - let paragraphStyle = NSMutableParagraphStyle() - paragraphStyle.lineBreakMode = self.lineBreakMode - paragraphStyle.alignment = self.textAlignment - let attributes: [String : AnyObject] = [NSFontAttributeName: self.font, NSParagraphStyleAttributeName: paragraphStyle] - let contentSize: CGSize = self.text!.boundingRect( - with: self.frame.size, - options: ([.usesLineFragmentOrigin, .usesFontLeading]), - attributes: attributes, - context: nil - ).size - return contentSize - } - - func setFrameWithString(_ string: String, width: CGFloat) { - self.numberOfLines = 0 - let attributes: [String : AnyObject] = [ - NSFontAttributeName: self.font, - ] - let resultSize: CGSize = string.boundingRect( - with: CGSize(width: width, height: CGFloat.greatestFiniteMagnitude), - options: NSStringDrawingOptions.usesLineFragmentOrigin, - attributes: attributes, - context: nil - ).size - let resultHeight: CGFloat = resultSize.height - let resultWidth: CGFloat = resultSize.width - var frame: CGRect = self.frame - frame.size.height = resultHeight - frame.size.width = resultWidth - self.frame = frame - } -} diff --git a/TSWeChat/Helpers/UIScreen+Extension.swift b/TSWeChat/Helpers/UIScreen+Extension.swift deleted file mode 100644 index c765d3f..0000000 --- a/TSWeChat/Helpers/UIScreen+Extension.swift +++ /dev/null @@ -1,50 +0,0 @@ -// -// UIScreen+Extension.swift -// TSWeChat -// -// Created by Hilen on 11/3/15. -// Copyright © 2015 Hilen. All rights reserved. -// - -import Foundation - -public extension UIScreen { - class var size: CGSize { - return UIScreen.main.bounds.size - } - - class var width: CGFloat { - return UIScreen.main.bounds.size.width - } - - class var height: CGFloat { - return UIScreen.main.bounds.size.height - } - - class var orientationSize: CGSize { - let systemVersion = (UIDevice.current.systemVersion as NSString).floatValue - let isLand: Bool = UIInterfaceOrientationIsLandscape(UIApplication.shared.statusBarOrientation) - return (systemVersion > 8.0 && isLand) ? UIScreen.SwapSize(self.size) : self.size - } - - class var orientationWidth: CGFloat { - return self.orientationSize.width - } - - class var orientationHeight: CGFloat { - return self.orientationSize.height - } - - class var DPISize: CGSize { - let size: CGSize = UIScreen.main.bounds.size - let scale: CGFloat = UIScreen.main.scale - return CGSize(width: size.width * scale, height: size.height * scale) - } - - class func SwapSize(_ size: CGSize) -> CGSize { - return CGSize(width: size.height, height: size.width) - } -} - - -