假设我有这个方法:
- (void)placeView:(UIView*)theView withCenterIn:(CGPoint)centerPoint;
所以我传递了视图和一个指向视图中心的点。
但碰巧我不需要指定中心,只需要指定视图。
传递“nil”会导致错误。
请建议如何跳过中心点。
请记住,我需要像这样使用该方法:
- (void)placeView:(UIView*)theView withCenterIn:(CGPoint)centerPoint{
if(centerPoint == nil){//and I understand that it's a wrong comparison, as I cannot pass "nil" to CGPoint
//set a random center point
}
else{
//set that view to the specified point
}
}
提前致谢
你不能使用nil
作为“无点”指标,因为它仅适用于对象,并且CGPoint
is a struct
。 (正如 dasblinkenlight 已经说过的那样。)
在我的几何库中,我定义了一个“null”CGPoint
用作“无点”占位符,以及测试它的函数。由于a的组成部分CGPoint
are CGFloat
s, and float
s 已经有一个“无效值”表示——NAN
,在 math.h 中定义——我认为这是最好使用的:
// Get NAN definition
#include <math.h>
const CGPoint WSSCGPointNull = {(CGFloat)NAN, (CGFloat)NAN};
BOOL WSSCGPointIsNull( CGPoint point ){
return isnan(point.x) && isnan(point.y);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)