add FPSLabel

This commit is contained in:
nixzhu
2015-12-15 11:04:19 +08:00
parent 0008756fca
commit 79f3157edf
2 changed files with 61 additions and 0 deletions
+4
View File
@@ -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 = "<group>"; };
50F5AF981BBBD02A0033C9BC /* FeedMediaCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedMediaCell.xib; path = Views/Cells/FeedMedia/FeedMediaCell.xib; sourceTree = "<group>"; };
50FA9A431B661698009BF2A0 /* UIViewController+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIViewController+Yep.swift"; path = "Extensions/UIViewController+Yep.swift"; sourceTree = "<group>"; };
50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FPSLabel.swift; path = Views/Labels/FPSLabel.swift; sourceTree = "<group>"; };
6A56328C1BC90A4500397B53 /* DiscoverCardUserCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DiscoverCardUserCell.swift; path = Views/Cells/DiscoverCardUser/DiscoverCardUserCell.swift; sourceTree = "<group>"; };
6A56328D1BC90A4500397B53 /* DiscoverCardUserCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = DiscoverCardUserCell.xib; path = Views/Cells/DiscoverCardUser/DiscoverCardUserCell.xib; sourceTree = "<group>"; };
6A5632911BC911CB00397B53 /* DiscoverNormalUserCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DiscoverNormalUserCell.swift; path = Views/Cells/DiscoverNormalUser/DiscoverNormalUserCell.swift; sourceTree = "<group>"; };
@@ -2154,6 +2156,7 @@
isa = PBXGroup;
children = (
50F2B97A1B2EEAF800F840CC /* NavigationTitleLabel.swift */,
50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */,
);
name = Labels;
sourceTree = "<group>";
@@ -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 */,
+57
View File
@@ -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)
}
}