2012-01-25 20 views
0

イメージフルスクリーンに合わせて画面サイズに合わせてイメージをダウンロードしてサイズを変更する方法があります。最大画像サイズは(320x416)です。今、私はフルスクリーンのUIScrollViewを、私はinitWithFrameをスクリーン幅でXにシフトしてUIImageViewを作成し、UIScrollViewスペースを水平に追加しています。 UISmrollViewをUIScrollView [imgView setContentMode:UIViewContentModeLeft]内で作成した場合、問題はありません。 [imgView setContentMode:UIViewContentModeCenter]を使用すると、イメージがシフトされ、ループのすべてのカウントが右に半分の画面が追加されるため、最初のイメージを表示できます。iPhone UIImageView UIScrollViewの水平スクロール - センターイメージ?

ここは私のコードですが、誰かが私に何かを逃してくれるのですか?ありがとうございました。 私はNSLogをimgViewのinitWithFrame:CGRectMakeに入れましたが、座標はOKですが、Xの位置は320ピクセルだけシフトしており、scrollViewのimgViewを配置しても問題ありません。

- (void)setImages { 

    int screenWidth = self.view.frame.size.width; 
    int screenHeight = self.view.frame.size.height; 

    // I know count of images here => imageIndex 
    [mainView setContentSize:CGSizeMake(screenWidth * imageIndex, screenHeight)]; 

    int actualWidth = screenWidth; 

    for (int index = 0; index < imageIndex; index++) { 

     UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(actualWidth - screenWidth, 0, actualWidth, screenHeight)]; 

     ImageProcessing *impc = [[ImageProcessing alloc] init]; 
     UIImage *image = [UIImage imageWithData:[imagesNSDataArray objectAtIndex:index]]; 
     UIImage *resampled = [impc processImageToWidthAndHeight:image :screenWidth :screenHeight]; 

     // [imgView setContentMode:UIViewContentModeCenter]; 
     [imgView setContentMode:UIViewContentModeLeft]; 
     imgView.image = resampled; 

     [mainView addSubview:imgView]; 

     actualWidth = actualWidth + screenWidth; 
    } 
} 

答えて

2

ビュー幅と水平位置が混在しています。ビューの幅は同じではありません。幅と幅を広げています。ビューをビューの中央に配置しようとすると、ビューが思ったよりも広いため、ビューが移動します。


int viewX = 0; 

for (int index = 0; index < imageCount; index++) { 
    CGRect frame = CGRectMake(viewX, 0, screenWidth, screenHeight); 
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:frame]; 

    [...] 

    viewX += screenWidth; 
} 
関連する問題