Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS如何找到CGRect的较大维度?_Ios_Geometry_Core Graphics_Cgrect - Fatal编程技术网

iOS如何找到CGRect的较大维度?

iOS如何找到CGRect的较大维度?,ios,geometry,core-graphics,cgrect,Ios,Geometry,Core Graphics,Cgrect,我知道core graphics有很多辅助函数,比如CGRectGetMidX。我正在使用autolayout并使用如下代码 float height = self.view.bounds.size.height * 0.08; UIImageView* key = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,height,height)]; 我可以使用三元运算符,但它看起来非常难看且不可读: float dimensio

我知道core graphics有很多辅助函数,比如
CGRectGetMidX
。我正在使用autolayout并使用如下代码

    float height = self.view.bounds.size.height * 0.08;
    UIImageView* key = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,height,height)];
我可以使用三元运算符,但它看起来非常难看且不可读:

float dimension = (self.view.bounds.size.height> self.view.bounds.size.width ?  self.view.bounds.size.height: self.view.bounds.size.width) * 0.08;
UIImageView* key = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,dimension,dimension)]
有没有一种方法可以将self.view.bounds.size.height替换为一个函数来获取矩形的最大尺寸,比如getMaxDimension(self.view.bounds)?

我知道我可以用if语句编写自己的语句,但我感兴趣的是,iOS中是否有某种东西可以让我用一个内置函数来实现这一点,这样我就可以在多个项目中使用相同的方法。

我想

MAX(CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
可能是从内置函数中获得的可读性最强的代码。 几何功能: MAX是objective-c运行时中的宏。 如果您希望代码更具可读性,只需编写自己的函数