在平時開發(fā)姜性,運行期間有時候想中途看一下某個視圖或變量的信息瞪慧,雖說打斷點是可以查看,但有時候斷點調試有時候會卡住好一會才能看到(尤其是大項目經(jīng)巢磕睿卡很久)弃酌,極度影響效率氨菇。
基于這種情況,FunnyButton
就是為了能夠便捷調試的全局按鈕妓湘,添加好調試事件查蓉,就能隨時點擊查看某個視圖或變量的信息,又可以直接調試某些函數(shù)榜贴。
Feature:
? 位于Window層級豌研,不會被app內的界面覆蓋;
? 自適應安全區(qū)域竣灌,自動靠邊聂沙,適配橫豎屏;
? 可執(zhí)行單個/多個調試事件初嘹;
? 兼容`iPhone`&`iPad`及汉;
? 兼容Objective-C環(huán)境調試;
? API簡單易用屯烦。
- GitHub傳送門
-
SwiftUI
版本:FunnyButton_SwiftUI
Effect
效果.gif
Basic use
為了兼容OC坷随,基于NSObject
的擴展提供給所有基類設置調試事件的接口,以UIViewController
為例:
- Swift
// 建議初始化好頁面時設置
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// 設置調試事件
replaceFunnyAction {
// 注意內存泄漏:閉包內部用到`self`記得使用`[weak self]`
print("點我干森莫")
}
}
// 建議頁面即將消失時移除這些事件
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// 移除調試事件
removeFunnyActions()
}
- Objective-C
// 建議初始化好頁面時設置
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// 設置調試事件
[self replaceFunnyActionWithWork:^{
// 注意內存泄漏:閉包內部用到`self`記得使用`__weak`
NSLog(@"點我干森莫");
}];
}
// 建議頁面即將消失時移除這些事件
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// 移除調試事件
[self removeFunnyActions];
}
API
FunnyButton.API.swift
- 公開可使用接口驻龟。
- replace action - 替換温眉、覆蓋全部事件
/// 替換單個`Action`
@objc func replaceFunnyAction(work: @escaping () -> ()) { ... }
/// 替換多個`Action`
@objc func replaceFunnyActions(_ actions: [FunnyAction]) { ... }
- add action - 在已有的事件上添加新的事件
/// 添加單個`Action`
@objc func addFunnyAction(name: String? = nil, work: @escaping () -> ()) { ... }
/// 添加多個`Action`
@objc func addFunnyActions(_ actions: [FunnyAction]) { ... }
- remove action - 刪除目標/全部事件
/// 帶條件移除目標`Action`(`decide`返回`true`則刪除)
@objc func removeFunnyActions(where decide: (FunnyAction) -> Bool) { ... }
/// 移除所有`Action`
@objc func removeFunnyActions() { ... }
- update layout - 刷新布局
/// 刷新`FunnyButton`布局
@objc func updateFunnyLayout() { ... }
Custom button UI
FunnyButton.swift
- 可改動的UI屬性均為靜態(tài)屬性,且有默認實現(xiàn)翁狐,如需改動建議啟動App時配置类溢。
public class FunnyButton: UIButton {
......
/// 普通狀態(tài)
static var normalEmoji = "??"
/// 點擊狀態(tài)
static var touchingEmoji = "??"
/// 毛玻璃樣式(nil為無毛玻璃)
static var effect: UIVisualEffect? = {
if #available(iOS 13, *) {
return UIBlurEffect(style: .systemThinMaterial)
}
return UIBlurEffect(style: .prominent)
}()
/// 背景色
static var bgColor: UIColor? = UIColor(red: 200.0 / 255.0, green: 100.0 / 255.0, blue: 100.0 / 255.0, alpha: 0.2)
/// 初始點(想`靠右/靠下`的話,`x/y`的值就設置大一點露懒,最后會靠在安全區(qū)域的邊上)
static var startPoint: CGPoint = CGPoint(x: 600, y: 100)
/// 安全區(qū)域的邊距
static var safeMargin: CGFloat = 12
......
}
// Initialization Example:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
......
FunnyButton.normalEmoji = "??"
FunnyButton.touchingEmoji = "??"
return true
}
Installation
FunnyButton is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'FunnyButton'
Author
Rogue24, zhoujianping24@hotmail.com