【问题标题】:how to implement photo slide show in iphone?如何在 iPhone 中实现照片幻灯片放映?
【发布时间】:2011-04-22 12:37:06
【问题描述】:

您好,我已经使用苹果的滚动示例实现了带有滚动视图和图像视图的照片幻灯片

- (void)viewDidLoad {

    kNumImages=[parray count];
    self.view.backgroundColor=[UIColor viewFlipsideBackgroundColor];
    [scrollView1 setBackgroundColor:[UIColor blackColor]];
    [scrollView1 setCanCancelContentTouches:NO];
    scrollView1.indicatorStyle=UIScrollViewIndicatorStyleWhite;
    scrollView1.clipsToBounds=YES;
    scrollView1.scrollEnabled=YES;   
    scrollView1.pagingEnabled=YES;
    scrollView1.minimumZoomScale=0.5;
    scrollView1.delegate=self;
    scrollView1.maximumZoomScale=6.0;
    NSUInteger i;
    for(i=0;i<kNumImages;i++)
    {

        NSURL *url=[NSURL URLWithString:[parray objectAtIndex:i]];
        NSLog(@"url object at index %i is %@",i,url);
        //NSString *imageName=[NSString stringWithFormat:@"image%d.jpg",i ];
        UIImage *image=[UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
        imageView=[[UIImageView alloc] initWithImage:image];
        CGRect rect=imageView.frame;
        rect.size.height=kScrollObjHeight;
        rect.size.width=kScrollObjWidth;
        imageView.frame=rect;
        imageView.tag=i+1;
        [scrollView1 addSubview:imageView];
        [imageView release];
    }

    [self layoutScrollImages];
    [super viewDidLoad];
}

-(void)layoutScrollImages
{
    kNumImages=[parray count];
    view=nil;
    NSArray *subviews=[scrollView1 subviews];
    CGFloat curXLoc=0;
    for(view in subviews)
    {
        if([view isKindOfClass:[UIImageView class]] && view.tag>0)
        {
            CGRect frame=view.frame;
            frame.origin=CGPointMake(curXLoc, 0);
            view.frame=frame;
            curXLoc+=(kScrollObjWidth);
        }}
    [scrollView1 setContentSize:CGSizeMake((kNumImages *kScrollObjWidth),[scrollView1 bounds].size.height)];

}

这很好用。但是这里的图像序列从图像数组中的第一张图像开始,而不是我想要任何图像说图像编号 3 想要在页面加载时首先出现在视图中,当我向左滚动时它应该显示图像 no .2 当我向右滚动时它应该显示图像 4.我该怎么做? 更新: 我已经使用以下代码解决了这个问题:

CGPoint lastFrame = CGPointMake(( 2* kScrollObjWidth), 0.0f);
[scrollView1 setContentOffset:lastFrame];

【问题讨论】:

    标签: iphone uiscrollview uiimageview image-gallery


    【解决方案1】:

    我已经使用以下代码解决了这个问题:

    CGPoint lastFrame = CGPointMake(( 2* kScrollObjWidth), 0.0f); [scrollView1 setContentOffset:lastFrame];

    【讨论】:

      【解决方案2】:

      您应该看看PageControl,它显示了分页如何与 UIScrollView 一起工作并将其连接到 UIPageControl。您可以轻松地调整该代码并按照您需要的顺序放入您的图像数组。它的内存效率很高:同时只使用三个 UIImageView。

      【讨论】:

      • 我已经使用以下代码解决了这个问题 CGPoint lastFrame = CGPointMake(( 2* kScrollObjWidth), 0.0f); [scrollView1 setContentOffset:lastFrame];
      • @NickWeaver PageControl 示例正是我正在寻找的。有快捷版吗?在 obj-c 中很难跟上。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多