问题描述
|
我正在使用包含0个值的1个值。有什么方法可以通过库方法来获得包含在数组中的所有rect的最大宽度,还是我必须实现自己的逻辑?提前致谢。
代码示例:
for (int i=0; i<[array1 count]; i++) {
CGRect rect = [[array1 objectAtIndex:i] CGRectValue];
// Here,some transformation of rects
[array2 addobject:[NSValue valueWithCGRect:rect]];
}
在这段代码中,我尝试从array1
中获取帧并将其添加到array2
中。我正在从XML中获得“ѭ3”中的帧。我解析了这些帧并将它们放置在数组中。我以非常简单的方式提供了代码。
解决方法
请勿一遍又一遍地向您的阵列发送“ 6”消息。这很浪费。
float result = 0.0;
for (value in array1)
{
GCRect rect = [value CGRectValue];
result = MAX(result,rect.size.width);
} // \"result\" now contains the greatest width you saw in the loop.
,for(int i=0; i < [array2 count]; i++)
{
CGRect rect = [[array2 objectAtIndex:i] CGRectValue];
float widthTest = rect.size.width;
//this gives you the width of each element. Compare and get the biggest
}