Closed doreamongit closed 3 years ago
在demo中直接调用 NSLog(@"%@",[NSValue valueWithCGRect:self.view.bounds]); 是能够打印的。 有可能是你在脚本中没有引入CGRect结构体的声明。 demo中相关的声明都在Scripts.bundle中。
不能识别UIView的bounds、center等属性
在 OCRunnerDemo 工程的 ViewController1.m 的 - (void)viewDidLoad { 方法中加入
UIView *frameView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 50, 50)]; frameView.backgroundColor = [UIColor redColor]; [self.view addSubview:frameView];
NSLog(@"----tapButton--11--:%@",self.view.subviews); NSLog(@"----tapButton--22--:%@",NSStringFromCGRect(self.view.frame)); NSLog(@"----:%@",NSStringFromCGPoint(self.view.center));
CGRect rect = CGRectMake(100, 100, 100, 100); NSLog(@"----:%@",NSStringFromCGRect(rect));
打印输出 2021-01-06 16:12:39.400790+0800 OCRunnerDemo[351:14130] ----tapButton--11--:( "<_UILayoutGuide: 0x102d151d0; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x1c0036040>>", "<_UILayoutGuide: 0x102d16020; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x1c0035d80>>", "<UIView: 0x102d05660; frame = (100 100; 50 50); layer = <CALayer: 0x1c0036320>>" ) 2021-01-06 16:12:39.400884+0800 OCRunnerDemo[351:14130] ----tapButton--22--:(null) 2021-01-06 16:12:39.400950+0800 OCRunnerDemo[351:14130] ----:(null) 2021-01-06 16:12:39.401100+0800 OCRunnerDemo[351:14130] ----:(null)
作者有时间辛苦帮忙看看。
... initWithFrame:CGRectMake(100, 100, 50, 50)]; 这里赋值的时候能够正常表现。
如果你要使用C函数,需要先引入函数的声明。结构体、枚举等同理,Scripts.bundle中的两个文件有示范。
针对你这个问题,可以将demo中的ViewController修改为:
NSString NSStringFromCGPoint(CGPoint point); NSString NSStringFromCGVector(CGVector vector); NSString NSStringFromCGSize(CGSize size); NSString NSStringFromCGRect(CGRect rect); NSString NSStringFromCGAffineTransform(CGAffineTransform transform); NSString NSStringFromUIEdgeInsets(UIEdgeInsets insets);
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIView *frameView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 50, 50)]; frameView.backgroundColor = [UIColor redColor]; [self.view addSubview:frameView]; NSLog(@"----tapButton--11--:%@",self.view.subviews); NSLog(@"----tapButton--22--:%@",NSStringFromCGRect(self.view.frame)); NSLog(@"----:%@",NSStringFromCGPoint(self.view.center)); CGRect rect = CGRectMake(100, 100, 100, 100); NSLog(@"----:%@",NSStringFromCGRect(rect)); }
感谢耐心细致的解答,其实在我的工程里边是有Scripts.bundle的,而且执行PatchGenerator脚本的时候,也能正常配置上, InputFiles: ["/Users/xxx/Documents/work/iOS/Lab/xxDemo/xxDemo/CustomeView/CustomeView.m", "/Users/xxx/Documents/work/iOS/Lab/xxDemo/xxDemo/CustomeView/CustomeView.h"] References: ["/Users/xxx/Library/Developer/Xcode/DerivedData/xxStreamDemo-btivpbzjrgypwmcbnfhlvgvawpxs/Build/Products/Debug/xxStreamDemo.app/Contents/Resources/Scripts.bundle/GCDRefrences", "/Users/xxx/Library/Developer/Xcode/DerivedData/xxStreamDemo-btivpbzjrgypwmcbnfhlvgvawpxs/Build/Products/Debug/xxStreamDemo.app/Contents/Resources/Scripts.bundle/UIKitRefrences"]
这个Scripts.bundle只在PatchGenerator生成补丁文件的时候用吧?在执行补丁文件的时候不用吧?
我这边发现了一个新情况 同一套代码里边,我用frame能正常获取,但是bounds获取的都是0。 在我这边的补丁源码文件里边 NSLog(@"----x:%f",self.bounds.origin.x); NSLog(@"----y:%f",self.bounds.origin.y); NSLog(@"----w:%f",self.bounds.size.width); NSLog(@"----h:%f",self.bounds.size.height);
NSLog(@"----x:%f",self.frame.origin.x); NSLog(@"----y:%f",self.frame.origin.y); NSLog(@"----w:%f",self.frame.size.width); NSLog(@"----h:%f",self.frame.size.height);
输出 ----x:0.000000 ----y:0.000000 ----w:0.000000 ----h:0.000000
----x:32.000000 ----y:45.000000 ----w:100.000000 ----h:100.000000
同样的代码,在OCRunnerDemo的工程里边正常运行。
Scripts.bundle表面上只是在生成补丁的时候使用了,但实际上,它会在补丁中占据一部分内容,后续OCRunner运行的时候,使用相关的声明。 关于: frame能正常获取,但是bounds获取的都是0。 相关代码直接在App里执行(不在脚本中使用)的时候,结果不相同吗?
Scripts.bundle表面上只是在生成补丁的时候使用了,但实际上,它会在补丁中占据一部分内容,后续OCRunner运行的时候,使用相关的声明。 关于: frame能正常获取,但是bounds获取的都是0。 相关代码直接在App里执行(不在脚本中使用)的时候,结果不相同吗?
你的意思是在那个二进制文件里边会有相关的内容对吧?
相关代码直接在APP里边能正常运行。
刚才我创建了一个全新的空工程,将 OCRunnerDemo 里边的 ORPatchFile.framework OCRunner.framework Scripts.bundle 复制过来,脚本也进行了相关配置 $SRCROOT/TestOCRunnerBounds/HotPatch/PatchGenerator -files $SRCROOT/TestOCRunnerBounds/HotPatch/Files -refs $SRCROOT/TestOCRunnerBounds/HotPatch/Scripts.bundle -output $SRCROOT/TestOCRunnerBounds/HotPatch/binarypatch
然后能正常获取bounds。
估计还是我这边工程的问题。
另外我之前集成的时候还需要,oc2mangoLib.framework ORPatchFile.bundle 现在是不需要这个了么?
二进制文件中,会有相关内容的。
将demo中的PatchGenerator、Scripts.bundle复制到工程中,然后在Podfile中添加pod 'OCRunner'
,pod install
即可。
如果是直接复制的话,PatchGenerator、Scripts.bundle、OCRunner.framework、ORPatchFile.framework。这些是必要文件。
使用2021-01-06 37b747fa829fb89dc977a8ad25a617523f30f9aa 这次提交编译出来的库,在我有问题的工程里边,重新集成了一次,能够正常使用,没有之前反馈的问题。作者辛苦!
使用2021-01-06 37b747f 这次提交编译出来的库,在我有问题的工程里边,重新集成了一次,能够正常使用,没有之前反馈的问题。作者辛苦!
请问,如果是使用最新的1.0.9版本,不知道能不能正常使用? 1.0.9是我刚提交的,可能需要使用pod repo update
后,才能获取到。
使用2021-01-06 37b747f 这次提交编译出来的库,在我有问题的工程里边,重新集成了一次,能够正常使用,没有之前反馈的问题。作者辛苦!
请问,如果是使用最新的1.0.9版本,不知道能不能正常使用? 1.0.9是我刚提交的,可能需要使用
pod repo update
后,才能获取到。
代码更新到 230c636698eca439a4b254b7b635a720c339ce18 使用 OCRunnerDemo 工程 pod install ➜ OCRunnerDemo git:(master) ✗ pod install Analyzing dependencies Downloading dependencies Installing OCRunner 1.0.9 (was 1.0.8) Generating Pods project Integrating client project Pod installation complete! There are 4 dependencies from the Podfile and 4 total pods installed.
然后用 OCRunnerDemo 编译出 OCRunner.framework ORPatchFile.framework ,加上 PatchGenerator Scripts.bundle 替换昨天说的全新的空工程,测试没有问题。
使用2021-01-06 37b747f 这次提交编译出来的库,在我有问题的工程里边,重新集成了一次,能够正常使用,没有之前反馈的问题。作者辛苦!
请问,如果是使用最新的1.0.9版本,不知道能不能正常使用? 1.0.9是我刚提交的,可能需要使用
pod repo update
后,才能获取到。代码更新到 230c636 使用 OCRunnerDemo 工程 pod install ➜ OCRunnerDemo git:(master) ✗ pod install Analyzing dependencies Downloading dependencies Installing OCRunner 1.0.9 (was 1.0.8) Generating Pods project Integrating client project Pod installation complete! There are 4 dependencies from the Podfile and 4 total pods installed.
然后用 OCRunnerDemo 编译出 OCRunner.framework ORPatchFile.framework ,加上 PatchGenerator Scripts.bundle 替换昨天说的全新的空工程,测试没有问题。
好的哟,谢谢🙏
不能识别UIView的bounds、center等属性
在 OCRunnerDemo 工程的 ViewController1.m 的 - (void)viewDidLoad { 方法中加入
UIView *frameView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 50, 50)]; frameView.backgroundColor = [UIColor redColor]; [self.view addSubview:frameView];
NSLog(@"----tapButton--11--:%@",self.view.subviews); NSLog(@"----tapButton--22--:%@",NSStringFromCGRect(self.view.frame)); NSLog(@"----:%@",NSStringFromCGPoint(self.view.center));
CGRect rect = CGRectMake(100, 100, 100, 100); NSLog(@"----:%@",NSStringFromCGRect(rect));
打印输出 2021-01-06 16:12:39.400790+0800 OCRunnerDemo[351:14130] ----tapButton--11--:( "<_UILayoutGuide: 0x102d151d0; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x1c0036040>>", "<_UILayoutGuide: 0x102d16020; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x1c0035d80>>", "<UIView: 0x102d05660; frame = (100 100; 50 50); layer = <CALayer: 0x1c0036320>>" ) 2021-01-06 16:12:39.400884+0800 OCRunnerDemo[351:14130] ----tapButton--22--:(null) 2021-01-06 16:12:39.400950+0800 OCRunnerDemo[351:14130] ----:(null) 2021-01-06 16:12:39.401100+0800 OCRunnerDemo[351:14130] ----:(null)
作者有时间辛苦帮忙看看。
... initWithFrame:CGRectMake(100, 100, 50, 50)]; 这里赋值的时候能够正常表现。