Ios 使用autolayout在uiscrollview中添加imageview

Ios 使用autolayout在uiscrollview中添加imageview,ios,objective-c,autolayout,Ios,Objective C,Autolayout,我有1个scrollview和许多imageview(1或2,它会有所不同)。我还在学习自动布局。我计划将图像视图添加到scrollview,从scrollview中内容的右侧开始 问题是 如何将imageview与scrollview的右侧内容关联?(不是滚动视图的右侧) initWithFrame可以在自动布局中使用吗 下面是我计划如何实施的想法草案。有什么好的/更好的方法吗?我可以知道怎么做吗 for(int item = 0; item < self.allData.count;

我有1个scrollview和许多imageview(1或2,它会有所不同)。我还在学习自动布局。我计划将图像视图添加到scrollview,从scrollview中内容的右侧开始

问题是

  • 如何将imageview与scrollview的右侧内容关联?(不是滚动视图的右侧)
  • initWithFrame
    可以在自动布局中使用吗
  • 下面是我计划如何实施的想法草案。有什么好的/更好的方法吗?我可以知道怎么做吗

    for(int item = 0; item < self.allData.count; item++)
    {
        UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(self.svAttractions.contentSize.width - width, 0, width, height)];
    
        if(item == 0)
        {
            //this is first item and I will add constraint to the right side of my image view to ride side content view of scrollview
            NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:img attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:?? attribute:NSLayoutAttributeRight multiplier:1.0 constant:10];
        }       
    
        if(item == self.allData.count - 1)
        {
            //this is last item and i will add constraint to the left side of image view to left side of content view of scrollview            
        }
        else
        {
            //this is not last item yet and i will add constrait to current right side image view to previous left side image view           
        }
    }
    
    for(int item=0;item

  • 您最好使用侧滚UICollectionView,因为您将拥有不同数量的图像。在右边“开始”内容有点奇怪,但是使用UICollectionView,您可以简单地颠倒数据的顺序,并在末尾开始contentOffset。