2012-05-06 16 views

答えて

8

一般的なアプローチは、ページングが有効になっているイメージの1つのサイズであるUIScrollViewです。

はサブビューとして画像を追加して、このようなコンテンツのサイズを設定...

NSArray *images; 
CGSize imageSize; 

self.scrollView.frame = CGRectMake(10,10,imageSize.width,imageSize.height); 
self.scrollView.contentSize = CGSizeMake(imageSize.width * images.count, imageSize.height); 
self.scrollView.pagingEnabled = YES; 

CGFloat xPos = 0.0; 

for (UIImage *image in images) { 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
    imageView.frame = CGRectMake(xPos, 0.0, imageSize.width, imageSize.width); 
    [self.scrollView addSubview:imageView]; 
    xPos += imageSize.width; 
    // assuming ARC, otherwise release imageView 
} 

また、あなたが望む効果の内容によってなど、指標をスクロール、バウンスをオフにすることがあります。 UIScrollViewのとUIPageControlを使用することにより

+0

を作成し、彼らは重複していないことを確認しUIScrollViewのとUIPageControlをドロップ私は、私が正しくあなたの提案を以下のいた場合確かに、それをしようとしませんでしたそれは動作しません、スクロールビューは空白のままです。多分、私はオブジェクト、イベントがどのように動作するのか理解できないために何かを見逃しています...ありがとう – Sweet

+0

この回答は私の問題を解決したリンクに私を導いた:http://www.iosdevnotes.com/2011/03/uiscrollview-ページング/。おかげでダン、私はそれを投票し、答えとしてマーク – Sweet

1

あなたは、単にスワイプ方向がUIImage配列と遊ぶのがあなたの前方と後方を扱うためのUISwipeGestureRecognizer

swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(detectSwipe:)]; 
[swipeGesture setNumberOfTouchesRequired:1]; 
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp]; 
[appView addGestureRecognizer:swipeGesture]; 

このような方法 detectSwipe宣言を左または右にされて得ることができます。あなたもチェックすることができます Apple's SimpleGestureRecognizers Demo

それはあなたを助けることを願っています!

2

、ドラッグ&N both.Set

のIBoutLet
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // 1 
imageArray = [NSArray arrayWithObjects: 
        [UIImage imageNamed:@"image2.jpg"], 
        [UIImage imageNamed:@"man-actor-Ashton-Kutcher-Wallpaper.jpg"], 
        [UIImage imageNamed:@"image1.jpg"], 
        [UIImage imageNamed:@"man-curl.jpg"], 
        [UIImage imageNamed:@"man-in-suit.jpg"], 
        nil]; 


    for (int i = 0; i < imageArray.count; i++) { 
    CGRect frame; 
    frame.origin.x = self.scrollView.frame.size.width * i; 
    frame.origin.y = 0; 
    frame.size = self.scrollView.frame.size; 

    UIImageView *subview = [[UIImageView alloc] initWithFrame:frame]; 
    subview.image = [imageArray objectAtIndex:i]; 
    subview.contentMode = UIViewContentModeScaleAspectFit; 
    [self.scrollView addSubview:subview]; 
    } 

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * imageArray.count, self.scrollView.frame.size.height); 
    pageControl.numberOfPages = imageArray.count; 
} 

- (void)scrollViewDidScroll:(UIScrollView *)sender { 
    // Update the page when more than 50% of the previous/next page is visible 
    CGFloat pageWidth = self.scrollView.frame.size.width; 
    int page = floor((self.scrollView.contentOffset.x - pageWidth/2)/pageWidth) + 1; 
    self.pageControl.currentPage = page; 
} 
関連する問題