2013-04-26 106 views
1

UPDATE:這似乎與自動佈局沒有任何關係。即使我禁用自動佈局我仍然得到同樣:(以編程方式向UIImageView添加約束條件

我加入了一系列UIImageView s到滾動視圖,並花費數小時試圖診斷 問題後,我得出它有結論,是指被推動的約束問題,我UIImage s下降,請參閱所附圖片:

enter image description here

正如你可以看到UIImage s的推下來,我已經標誌着UIScrollView紅色背景我也有附上我的UIScrollView的約束圖片:

enter image description here

這裏是我的滾動視圖的屬性:

enter image description here

如何獲得有關設置的UIImageView,使其在UIScrollView水平爲中心的約束?我正在使用以下代碼將圖像填入UIScrollView

for (UIView *v in self.scrollview.subviews) 
    { 
     [v removeFromSuperview]; 
    } 

    CGRect workingFrame = self.scrollview.frame; 
    workingFrame.origin.x = 0; 

    for(NSDictionary *dict in info) 
    { 

     UIImageView *imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]]; 

     MyManager * myManager = [MyManager sharedInstance]; 
     [myManager.assets addObject:imageview]; 
     [imageview setContentMode:UIViewContentModeScaleAspectFit]; 
     imageview.frame = workingFrame; 
     [self.scrollview addSubview:imageview]; 
     workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width; 
    } 

    [self.scrollview setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)]; 
+0

redcolor是textview? – 2013-04-26 03:57:13

+0

uiscrollview後面有一個textview,當點擊頂部的uisegment按鈕的「文本」時顯示。 – jini 2013-04-26 03:59:41

+0

紅色是滾動視圖 – jini 2013-04-26 04:06:35

回答

0

workingFrame.origin.y = 0;修復它

相關問題