如何使用滑动手势创建用于显示照片的图库?

时间:2011-12-26 16:59:49

标签: iphone cocoa-touch ipad uigesturerecognizer swipe

我在NSArray中有多张照片,我希望使用全尺寸的滑动手势显示它们而不使用Three20。那我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

使用scrollView来完成:

UIScrollView * scroller = [[[UIScrollView alloc] initWithFrame:CGTectMake(0, 0, 320, 480)] autorelease];
scroller.pagingEnabled = YES;
[self.view addSubview:scroller];

int x = 0;

for (int i = 0; i < [yourArray count]; i++){

    UIImageView * myImageview = [[[UIImageView alloc] initWithFrame:CGRectMake(x, 0, 320, 480)] autorelease];
    [myImageview setImage:[yourArray objectAtIndex:i]];
    [scroller addSubview:myView];

    x += myView.frame.size.width;

}

[scroller setContentSize:CGSizeMake(x, 480)];

答案 1 :(得分:1)

本守则对我很有用:

self.view.backgroundColor = [UIColor redColor];
 UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
 scroll.pagingEnabled = YES;
 NSInteger numberOfViews = 3;
 for (int i = 0; i < numberOfViews; i++) {
  CGFloat yOrigin = i * self.view.frame.size.width;
  UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
  awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
  [scroll addSubview:awesomeView];
   [awesomeView release];
  }
  scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
  [self.view addSubview:scroll];
  [scroll release];