Objective-C自动在UI滚动视图中滚动图像,如水平幻灯片放映

时间:2013-09-26 07:03:11

标签: iphone objective-c uiscrollview autoscroll

我有一个从数据库进入iMagesArray的图像列表。

我的要求是以水平固定尺寸窗口的幻灯片形式显示图片

http://www.nda4u.com/ * 中的

同样谢谢2013年NDA会议赞助商: * line

1 个答案:

答案 0 :(得分:-1)

尝试

//...
int i;
}
-(void) viewDidLoad{
//... whatever wour code in the view is...
    [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(animation:) userInfo:Nil repeats:Yes];
}

-(void)animation{
    i++;
    //i'd name the images just with numbers
    int newView = mod(i,numberOfImagesInSlideShow);
    NSString *name = [NSString stringWithFormat:@"%d",mod(i,numberOfTotalImages);]
    UIImageView newImageView = [[UIImageView alloc] initWithImage[UIImage imageNamed:name]];
    self.imageView.center = CGPointMake(-self.bounds.size.width/numberOfImagesInSlideShow,self.bounds.size.height/2);

    [self addSubView:newImageView];
    [UIView animateWithDuration:2.0f animations:^{
        for(int n=0;n<numberOfImagesInSlideShow;n++){
            if([self viewWithTag:(mod(i+n,numberOfImagesInSlideShow))])
                [self viewWithTag:(mod(i+n,numberOfImagesInSlideShow))].center = CGPointMake(n*self.bounds.size.width/numberOfImagesInSlideShow,self.bounds.size.height/2);
        }
     }                               completion:^(BOOL finished){
        if([self viewWithTag:(mod(mod(i+numberOfImagesInSlideShow-1,numberOfImagesInSlideShow)))])
                [[self viewWithTag:(mod(i+numberOfImagesInSlideShow-1,numberOfImagesInSlideShow))] removeFromSuperView];
     }];