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
相關文章
- 震驚!iOS 系統居然自帶懸浮視窗除錯工具 —— Jinkey 原創iOS除錯
- Android 懸浮窗Android
- Andorid 任意介面懸浮窗,實現懸浮窗如此簡單
- 懸浮窗的一種實現 | Android懸浮窗Window應用Android
- Android 懸浮窗 System Alert WindowAndroid
- QPM 之懸浮窗設定資訊
- Android懸浮窗的學習Android
- ios 除錯工具iOS除錯
- QPM 之懸浮窗助力效能優化優化
- 懸浮窗開發設計實踐
- HTML 滑鼠放上顯示懸浮視窗HTML
- Android 懸浮視窗的實現Android
- 固定位置的Js懸浮視窗JS
- Android 攝像頭預覽懸浮窗Android
- Android仿微信文章懸浮窗效果Android
- Android懸浮窗--獲取記憶體Android記憶體
- 小米 TYPE_TOAST 懸浮窗無效的原因AST
- Android 輔助許可權與懸浮窗Android
- 【轉載】使用WindowManage實現Android懸浮窗Android
- FloatWindow 輕鬆實現安卓任意介面懸浮窗安卓
- iOS:高仿微信文章懸浮球iOS
- 百度地圖新增懸浮窗搜尋功能地圖
- 直播原始碼,懸浮窗滾動漸變色效果原始碼
- Android應用內懸浮窗的實現方案Android
- 類似網路螞蟻的懸浮窗體 (轉)
- Android懸浮窗TYPE_TOAST小結: 原始碼分析AndroidAST原始碼
- oracle 自帶錯誤提示工具oerrOracle
- Android開發筆記(一百一十八)自定義懸浮窗Android筆記
- Android實現仿360手機衛士懸浮窗效果Android
- Android 為應用增加可移動的懸浮視窗Android
- vue 本地除錯跨域---帶cookies(axios)Vue除錯跨域CookieiOS
- MIUI 8“懸浮球”下放MIUI 7:功能完爆iOSUIiOS
- 記一次懸浮窗的上線以及坑點總結
- 如何獲取Vivo系統的懸浮窗許可權狀態
- Android實現流量統計和網速監控懸浮窗Android
- ALaunch 0.8 := 懸浮提示
- LLDebugTool – 便捷的IOS除錯工具(Version 1.1.5)iOS除錯
- LLDebugTool - 便捷的IOS除錯工具(Version 1.1.3)iOS除錯