如何创建一个画廊来使用滑动手势显示照片?

发布于 2024-12-23 02:04:50 字数 114 浏览 2 评论 0原文

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

I have multiple photos in an NSArray and i want to display them with the swipe gesture in full size without using Three20 . so how can i do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请恋爱 2024-12-30 02:04:50

使用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)];

Use a scrollView for accomplish that :

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)];
南七夏 2024-12-30 02:04:50

这段代码对我来说非常有用:

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];

This Code works for me great:

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文