From 79f3157edfb7652dadcbebb678fe8774d1d67a56 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 15 Dec 2015 11:04:19 +0800 Subject: [PATCH 01/10] add FPSLabel --- Yep.xcodeproj/project.pbxproj | 4 +++ Yep/Views/Labels/FPSLabel.swift | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 Yep/Views/Labels/FPSLabel.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 8b24c3fc..dab817cc 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -320,6 +320,7 @@ 50F5AF991BBBD02A0033C9BC /* FeedMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */; }; 50F5AF9A1BBBD02A0033C9BC /* FeedMediaCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF981BBBD02A0033C9BC /* FeedMediaCell.xib */; }; 50FA9A441B661698009BF2A0 /* UIViewController+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FA9A431B661698009BF2A0 /* UIViewController+Yep.swift */; }; + 50FD753D1C1FB4AC0050A382 /* FPSLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */; }; 6A56328E1BC90A4500397B53 /* DiscoverCardUserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A56328C1BC90A4500397B53 /* DiscoverCardUserCell.swift */; }; 6A56328F1BC90A4500397B53 /* DiscoverCardUserCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6A56328D1BC90A4500397B53 /* DiscoverCardUserCell.xib */; }; 6A5632931BC911CB00397B53 /* DiscoverNormalUserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A5632911BC911CB00397B53 /* DiscoverNormalUserCell.swift */; }; @@ -678,6 +679,7 @@ 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaCell.swift; path = Views/Cells/FeedMedia/FeedMediaCell.swift; sourceTree = ""; }; 50F5AF981BBBD02A0033C9BC /* FeedMediaCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedMediaCell.xib; path = Views/Cells/FeedMedia/FeedMediaCell.xib; sourceTree = ""; }; 50FA9A431B661698009BF2A0 /* UIViewController+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIViewController+Yep.swift"; path = "Extensions/UIViewController+Yep.swift"; sourceTree = ""; }; + 50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FPSLabel.swift; path = Views/Labels/FPSLabel.swift; sourceTree = ""; }; 6A56328C1BC90A4500397B53 /* DiscoverCardUserCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DiscoverCardUserCell.swift; path = Views/Cells/DiscoverCardUser/DiscoverCardUserCell.swift; sourceTree = ""; }; 6A56328D1BC90A4500397B53 /* DiscoverCardUserCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = DiscoverCardUserCell.xib; path = Views/Cells/DiscoverCardUser/DiscoverCardUserCell.xib; sourceTree = ""; }; 6A5632911BC911CB00397B53 /* DiscoverNormalUserCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DiscoverNormalUserCell.swift; path = Views/Cells/DiscoverNormalUser/DiscoverNormalUserCell.swift; sourceTree = ""; }; @@ -2154,6 +2156,7 @@ isa = PBXGroup; children = ( 50F2B97A1B2EEAF800F840CC /* NavigationTitleLabel.swift */, + 50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */, ); name = Labels; sourceTree = ""; @@ -2798,6 +2801,7 @@ 50F2B97B1B2EEAF800F840CC /* NavigationTitleLabel.swift in Sources */, 501690231BFEA6C30096C4F9 /* FeedBasicCell.swift in Sources */, 50A820241B969B0F007CD30E /* NSTimeZone+Yep.swift in Sources */, + 50FD753D1C1FB4AC0050A382 /* FPSLabel.swift in Sources */, 504F415A1AD5028200FBB19A /* SkillCell.swift in Sources */, 84385C481B85AC890071130D /* ShowStepMatchViewController.swift in Sources */, 0A0027D61B19CEC000AD4BE0 /* ConversationOperationQueue.swift in Sources */, diff --git a/Yep/Views/Labels/FPSLabel.swift b/Yep/Views/Labels/FPSLabel.swift new file mode 100644 index 00000000..35966187 --- /dev/null +++ b/Yep/Views/Labels/FPSLabel.swift @@ -0,0 +1,57 @@ +// +// FPSLabel.swift +// Yep +// +// Created by nixzhu on 15/12/15. +// Copyright © 2015年 Catch Inc. All rights reserved. +// + +import UIKit + +class FPSLabel: UILabel { + + private var displayLink: CADisplayLink? + private var lastTime: NSTimeInterval = 0 + private var count: Int = 0 + + deinit { + displayLink?.invalidate() + } + + override func didMoveToSuperview() { + super.didMoveToSuperview() + + run() + } + + func run() { + + displayLink = CADisplayLink(target: self, selector: "tick:") + displayLink?.addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes) + } + + func tick(displayLink: CADisplayLink) { + + if lastTime == 0 { + lastTime = displayLink.timestamp + return + } + + count += 1 + + let timeDelta = displayLink.timestamp - lastTime + + if timeDelta < 1 { + return + } + + lastTime = displayLink.timestamp + + let fps: Double = Double(count) / timeDelta + + count = 0 + + text = String(format: "%.1f", fps) + } +} + From 1072acc681915e358abb17b05914e3cf848853a4 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 15 Dec 2015 11:10:26 +0800 Subject: [PATCH 02/10] use feedsFPSLabel for DEBUG --- Yep/ViewControllers/Feeds/FeedsViewController.swift | 9 +++++++++ Yep/Views/Labels/FPSLabel.swift | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 4e6db7c8..39f7710a 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -99,6 +99,11 @@ class FeedsViewController: BaseViewController { return pullToRefreshView }() + private lazy var feedsFPSLabel: FPSLabel = { + let label = FPSLabel() + return label + }() + private let feedSkillUsersCellID = "FeedSkillUsersCell" private let feedCellID = "FeedCell" private let feedSocialWorkCellID = "FeedSocialWorkCell" @@ -306,6 +311,10 @@ class FeedsViewController: BaseViewController { } } } + + #if DEBUG + view.addSubview(feedsFPSLabel) + #endif } // MARK: Actions diff --git a/Yep/Views/Labels/FPSLabel.swift b/Yep/Views/Labels/FPSLabel.swift index 35966187..02ee03e1 100644 --- a/Yep/Views/Labels/FPSLabel.swift +++ b/Yep/Views/Labels/FPSLabel.swift @@ -21,6 +21,14 @@ class FPSLabel: UILabel { override func didMoveToSuperview() { super.didMoveToSuperview() + frame = CGRect(x: 15, y: 150, width: 40, height: 40) + layer.cornerRadius = 20 + clipsToBounds = true + backgroundColor = UIColor.blackColor() + textColor = UIColor.greenColor() + textAlignment = .Center + font = UIFont.systemFontOfSize(24) + run() } @@ -51,7 +59,7 @@ class FPSLabel: UILabel { count = 0 - text = String(format: "%.1f", fps) + text = String(format: "%.0f", fps) } } From 15f3a56a52d3cb6228980195eeb2b1c9ac842b9b Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 15 Dec 2015 13:12:01 +0800 Subject: [PATCH 03/10] set opaque of subviews for Feed Cells --- Yep/Views/Cells/Feed/FeedCell.xib | 30 ++++++------ .../FeedSocialWork/FeedSocialWorkCell.xib | 46 ++++++++++++------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedCell.xib b/Yep/Views/Cells/Feed/FeedCell.xib index cf0a0fd1..d7378156 100644 --- a/Yep/Views/Cells/Feed/FeedCell.xib +++ b/Yep/Views/Cells/Feed/FeedCell.xib @@ -1,8 +1,8 @@ - + - + @@ -11,20 +11,19 @@ - + - @@ -35,46 +34,46 @@ - - @@ -123,7 +122,6 @@ - diff --git a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.xib b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.xib index 49b9c793..eedaedd9 100644 --- a/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.xib +++ b/Yep/Views/Cells/FeedSocialWork/FeedSocialWorkCell.xib @@ -1,8 +1,8 @@ - + - + @@ -11,18 +11,20 @@ - + -