此函数因运行时错误而失败:
-[UIWindow viewForFirstBaselineLayout]: unrecognized selector sent to instance 0x7fb9dae257d0
Run Code Online (Sandbox Code Playgroud)
有人遇到过同样的事吗?
UPD:
在iOS 8.1/8.4模拟器上失败.9.3工作正常.
UPD2:
UIWindow创建如下:
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = RootViewController.rootVC
window?.makeKeyAndVisible()
Run Code Online (Sandbox Code Playgroud)
And*_*eev 21
看起来Xcode 7.3使用viewForFirstBaselineLayout属性来绘制UI.但是,自iOS 9.0起,此属性已标记为可用.
[UIView viewForFirstBaselineLayout]方法应该用于iOS 9.0之前的版本.似乎苹果公司的人不考虑这个案子.
Bri*_*kel 21
通过在我的项目中放置以下修复,我使视图调试器再次工作:
#ifdef DEBUG
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
@implementation UIView (FixViewDebugging)
+ (void)load
{
Method original = class_getInstanceMethod(self, @selector(viewForBaselineLayout));
class_addMethod(self, @selector(viewForFirstBaselineLayout), method_getImplementation(original), method_getTypeEncoding(original));
class_addMethod(self, @selector(viewForLastBaselineLayout), method_getImplementation(original), method_getTypeEncoding(original));
}
@end
#endif
Run Code Online (Sandbox Code Playgroud)
当您的项目加载时,该load方法将执行,导致viewForFirstBaselineLayout并viewForLastBaselineLayout使用viewForBaselineLayout实现(如果它们当前未实现),因此视图调试将获得iOS8风格它正在寻找的行为.
要将其添加到您自己的项目中,请在项目中创建一个新的空Objective-C文件并粘贴内容.您可以根据需要为其命名.我称之为"UIView + FixViewDebugging".如果您使用的是纯Swift项目,则无需创建桥接标头.该文件将被编译到您的项目中,您无需参考它.
请注意,这仅适用于调试版本,因为#ifdef DEBUG.您可以删除它,但之后您可能会意外地将其编译到您的发布版本中(尽管它应该没有不良副作用).如果此方法不适用于这些行,请检查目标是否DEBUG=1在"构建设置">"Apple LLVM - 预处理">"预处理器宏">"调试"中.
| 归档时间: |
|
| 查看次数: |
5237 次 |
| 最近记录: |