我有一系列正在创建的按钮。但是,当我调用 setCenter 时,代码会崩溃。
buttonsArray = [NSMutableArray new];
for (int i = 0; i < 7; i++) {
[buttonsArray addObject:[UIButton buttonWithType:UIButtonTypeCustom]];
UIButton *tempButton = [buttonsArray objectAtIndex:i];
[tempButton setFrameWidth:300.0 andHeight:50.0];
[tempButton addBlackBorderWidth:1.0];
[tempButton roundCornersBy:10.0];
[tempButton setBackgroundColor:[UIColor blackColor]];
[tempButton setColorToGradientFromColor:[UIColor grayColor] toColor:[UIColor blackColor]];
[tempButton setButtonTextColorForNormalState:[UIColor whiteColor] highlightedState:[UIColor redColor]];
[tempButton setCenter:CGPointMake([self screenUsableWidth] / 2.0, ([self screenUsableHeight] - 2.0 * MAIN_MENU_BUTTON_TO_SIDE_DISTANCE) * i / ([buttonsArray count] - 1) + MAIN_MENU_BUTTON_TO_SIDE_DISTANCE)]; //crash is here
}
错误是*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [384 nan]'