CALayer的position属性包含NaN:[nan -__]

5

由于CALayerInvalidGeometry异常而终止应用程序,原因是'CALayer position contains NaN: [nan 81]' // 81为运行时更改。

第一个抛出的调用堆栈:

(
0   CoreFoundation                      0x000000011041a34b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x000000010f84021e objc_exception_throw + 48
2   CoreFoundation                      0x0000000110483265 +[NSException raise:format:] + 197
3   QuartzCore                          0x000000010c4842f2 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
4   QuartzCore                          0x000000010c484467 -[CALayer setPosition:] + 44
5   UIKit                               0x000000010c7e18d2 -[UIView setCenter:] + 233
6   Hi2Buy                              0x000000010bf517e1 -[RangeSlider layoutSubviews] + 193
7   UIKit                               0x000000010c807344 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
8   QuartzCore                          0x000000010c48dcdc -[CALayer layoutSublayers] + 146
9   QuartzCore                          0x000000010c4817a0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
10  QuartzCore                          0x000000010c48161e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
11  QuartzCore                          0x000000010c40f62c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
12  QuartzCore                          0x000000010c43c713 _ZN2CA11Transaction6commitEv + 475
13  QuartzCore                          0x000000010c43d083 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113
14  CoreFoundation                      0x00000001103bee17 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
15  CoreFoundation                      0x00000001103bed87 __CFRunLoopDoObservers + 391
16  CoreFoundation                      0x00000001103a3b9e __CFRunLoopRun + 1198
17  CoreFoundation                      0x00000001103a3494 CFRunLoopRunSpecific + 420
18  GraphicsServices                    0x0000000112daba6f GSEventRunModal + 161
19  UIKit                               0x000000010c742f34 UIApplicationMain + 159
20  Hi2Buy                              0x000000010bfa3ddf main + 111
21  libdyld.dylib                       0x0000000111d7068d start + 1
22  ???                                 0x0000000000000001 0x0 + 1
)

libc++abi.dylib: terminating with uncaught exception of type NSException

我的代码:
RangeSlider *slider=  [[RangeSlider alloc] initWithFrame:self.viewSlider.bounds];
[slider addTarget:self action:@selector(slidreDrag:) forControlEvents:UIControlEventValueChanged];           
[self.viewSlider addSubview:slider];

也许你自定义的控件RangeSlider存在问题,请仔细检查layout subviews方法中的代码。 - Igor Kislyuk
1
如果您提供RangeSlider的代码,我们就更有可能找到问题。 - alexburtnik
1个回答

2
解决这个问题的方法是:
RangeSlider *slider=  [[RangeSlider alloc] initWithFrame:self.viewSlider.bounds];
slider.minimumValue = [minValue floatValue]; 
slider.selectedMinimumValue = [minValue floatValue];
slider.maximumValue = [maxValue floatValue];
slider.selectedMaximumValue = [maxValue floatValue];
slider.minimumRange = 2;
[slider addTarget:self action:@selector(slidreDrag:) forControlEvents:UIControlEventValueChanged];           
[self.viewSlider addSubview:slider];

原因

you are doesn't set value of minimum, maximum that this value by default select NaN value this type error occur.

Please set value.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接