Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
Objective c UIView上的UIImage排序_Objective C_Uiview_Uiimage - Fatal编程技术网

Objective c UIView上的UIImage排序

Objective c UIView上的UIImage排序,objective-c,uiview,uiimage,Objective C,Uiview,Uiimage,我马上就要得到我想要的了。最后的部分是最难的。所以基本上我的最后一个视图是一个最多可以看到6个UIImages的视图。并在屏幕上进行排序,使其具有相同的比率: 示例: 视图: 因此,在屏幕中央,这将是2个相同比例的UIImage 示例2 视图: 在我看来,这将是3个图像 我可以通过做一个很长的If/else语句和故事板中的很多视图来硬编码。但我希望能找到一个正确的解决方案 我需要如何解决这个问题 问候 你应该试试这样的东西:(未经测试,给你一个想法) NSInteger itemInRow=2;

我马上就要得到我想要的了。最后的部分是最难的。所以基本上我的最后一个视图是一个最多可以看到6个UIImages的视图。并在屏幕上进行排序,使其具有相同的比率:

示例: 视图:

因此,在屏幕中央,这将是2个相同比例的UIImage

示例2 视图:

在我看来,这将是3个图像

我可以通过做一个很长的If/else语句和故事板中的很多视图来硬编码。但我希望能找到一个正确的解决方案

我需要如何解决这个问题


问候

你应该试试这样的东西:(未经测试,给你一个想法)

NSInteger itemInRow=2;
NSInteger itemsunt=6;//假设6
NSInteger imageViewWidth=myImageView.frame.size.width;
NSInteger imageViewHeight=myImageView.frame.size.height;
NSInteger leftMargin=(imageViewWidth*itemInRow)/2;

对于(int i=1;i)如果我理解正确,您希望根据图像大小进行动态布局吗?请尝试集合视图
-------
  UI
  UI
-------
-------
UI  UI
  UI
-------
NSInteger itemInRow = 2;
NSInteger itemsCount = 6;  // Assume 6
NSInteger imageViewWidth = myImageView.frame.size.width;
NSInteger imageViewHeight = myImageView.frame.size.height;
NSInteger leftMargin = (imageViewWidth * itemInRow) / 2;

for(int i = 1; i <= itemsCount / itemInRow; i++)
{
    myImageView.center = CGPointMake((imageViewWidth + leftMargin) * i, imageViewHeight * i);
}