iOS自帶懸浮窗除錯工具
[九九Tips]- http://www.jianshu.com/users/bab86b3e8aa3/latest_articles
參考的部落格:
https://wellphone.me/post/2017/use_uidebugginginformationoverlay_to_debug_ui/
使用步驟(簡化版):
先把檔案
UIDebuggingInformationOverlay+Enable.m
放在拖到工程裡,這個檔案內容放在文章的結尾處。在
didFinishLaunchingWithOptions
方法中貼上下面一段程式碼
#ifdef DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
id overlayClass = NSClassFromString(@"UIDebuggingInformationOverlay");
[overlayClass performSelector:NSSelectorFromString(@"prepareDebuggingOverlay")];
#pragma clang diagnostic pop
#endif
- 執行後,用兩個手指頭在狀態列上同時點選下就可以顯示出這個除錯的懸浮層。
執行效果
你值得擁有~
下面的程式碼為附件檔案,請儲存為 UIDebuggingInformationOverlay+Enable.m 格式拖到工程目錄下:
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
/*
In iOS 11, Apple added additional checks to disable this overlay unless the
device is an internal device. To get around this, we swizzle out the
-[UIDebuggingInformationOverlay init] method (which returns nil now if
the device is non-internal) and +[UIDebuggingInformationOverlay prepareDebuggingOverlay]
method.
Usage:
1.Copy this file to your project.
2.Add the following code to [AppDelegate application:didFinishLaunchingWithOptions:]
#if DEBUG
id overlayClass = NSClassFromString(@"UIDebuggingInformationOverlay");
[overlayClass performSelector:NSSelectorFromString(@"prepareDebuggingOverlay")];
#endif
*/
#if defined(DEBUG) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincomplete-implementation"
#pragma clang diagnostic ignored "-Wundeclared-selector"
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
@interface UIWindow (PrivateMethods)
- (void)_setWindowControlsStatusBarOrientation:(BOOL)orientation;
@end
@interface FakeWindowClass : UIWindow
@end
@implementation FakeWindowClass
- (instancetype)initSwizzled {
self = [super init];
if (self) {
[self _setWindowControlsStatusBarOrientation:NO];
}
return self;
}
@end
@implementation NSObject (UIDebuggingInformationOverlayEnable)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class cls = NSClassFromString(@"UIDebuggingInformationOverlay");
[FakeWindowClass swizzleSelector:@selector(init) newSelector:@selector(initSwizzled) forClass:cls isClassMethod:NO];
[self swizzleSelector:@selector(prepareDebuggingOverlay) newSelector:@selector(prepareDebuggingOverlaySwizzled) forClass:cls isClassMethod:YES];
});
}
+ (void)swizzleSelector:(SEL)originalSelector newSelector:(SEL)swizzledSelector forClass:(Class)class isClassMethod:(BOOL)isClassMethod {
Method originalMethod = NULL;
Method swizzledMethod = NULL;
if (isClassMethod) {
originalMethod = class_getClassMethod(class, originalSelector);
swizzledMethod = class_getClassMethod([self class], swizzledSelector);
} else {
originalMethod = class_getInstanceMethod(class, originalSelector);
swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);
}
method_exchangeImplementations(originalMethod, swizzledMethod);
}
+ (void)prepareDebuggingOverlaySwizzled {
id overlayClass = NSClassFromString(@"UIDebuggingInformationOverlayInvokeGestureHandler");
id handler = [overlayClass performSelector:NSSelectorFromString(@"mainHandler")];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:handler action:@selector(_handleActivationGesture:)];
tapGesture.numberOfTouchesRequired = 2;
tapGesture.numberOfTapsRequired = 1;
tapGesture.delegate = handler;
UIView *statusBarWindow = [[UIApplication sharedApplication] valueForKey:@"statusBarWindow"];
[statusBarWindow addGestureRecognizer:tapGesture];
}
@end
#pragma clang diagnostic pop
#endif
相關文章
- Android 懸浮窗Android
- 懸浮窗的一種實現 | Android懸浮窗Window應用Android
- Android懸浮窗的學習Android
- Android 懸浮窗 System Alert WindowAndroid
- QPM 之懸浮窗設定資訊
- QPM 之懸浮窗助力效能優化優化
- Android仿微信文章懸浮窗效果Android
- Android 攝像頭預覽懸浮窗Android
- 懸浮窗開發設計實踐
- 【轉載】使用WindowManage實現Android懸浮窗Android
- Android 輔助許可權與懸浮窗Android
- iOS:高仿微信文章懸浮球iOS
- 小米 TYPE_TOAST 懸浮窗無效的原因AST
- 百度地圖新增懸浮窗搜尋功能地圖
- 直播原始碼,懸浮窗滾動漸變色效果原始碼
- LLDebugTool – 便捷的IOS除錯工具(Version 1.1.5)iOS除錯
- LLDebugTool - 便捷的IOS除錯工具(支援Swift)iOS除錯Swift
- LLDebugTool - 便捷的IOS除錯工具(Version 1.1.3)iOS除錯
- LLDebugTool - 便捷的IOS除錯工具(Version 1.1.5)iOS除錯
- LLDebugTool - 便捷的IOS除錯工具(支援元件化)iOS除錯元件化
- iOS - 新增一個全域性懸浮按鈕(整合pods版)iOS
- 記一次懸浮窗的上線以及坑點總結
- 下沉式通知的一種實現 | Android懸浮窗Window應用Android
- 如何獲取Vivo系統的懸浮窗許可權狀態
- ALaunch 0.8 := 懸浮提示
- 非侵入式無許可權應用內懸浮窗的實現
- Android中的懸浮框Android
- Fluid Browser for Mac(多工懸浮透明視窗瀏覽器)1.6啟用版UIMac瀏覽器
- 直播平臺製作,Android 懸浮窗延時5秒返回APP問題AndroidAPP
- 電商直播主圖設計素材,輕鬆搞定直播懸浮窗設計!
- 2小時內封裝一個 Flutter 仿iOS全屏移動懸浮窗?幹就完了! |8月更文挑戰封裝FlutteriOS
- JS錯誤記錄 – 右側懸浮框 – 緩衝運動JS
- 直播app開發,推出語音聊天室時保持懸浮窗存在狀態APP
- Android懸浮框的實現Android
- 底部導航欄懸浮效果
- css做個波浪懸浮球?CSS
- Android懸浮窗怎麼簡單實現?這樣用 kotlin編寫輕鬆搞定!AndroidKotlin
- 短視訊app原始碼,連麥時最小化出現可移動懸浮窗APP原始碼
- Android 攝像頭預覽懸浮窗,可拖動,可顯示在其他app上方AndroidAPP