iPhone上实现图片自动转页功能

原帖地址  http://www.cocoachina.com/bbs/read.php?tid-10964.html

这是一个在苹果iPhone上实现图片自动转页功能的源代码,供新手参考。

//
//  autoPageViewController.m
//  autoPage
//
//  Created by Lixf on 09-11-18.
//  Copyright Lixf 2009. All rights reserved.
//

#import "autoPageViewController.h"
#import "ImageDataView.h"
@implementation autoPageViewController
@synthesize Timer;
@synthesize imageData;
@synthesize imgView;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    Page = 0;
    
    //初始化图片数据
    ImageDataView *data = [[ImageDataView alloc] init];
    self.imageData = data;
    [data release];
    
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 44, 320, 436)];
    [img setImage:[UIImage imageNamed:[imageData.imgArray objectAtIndex:Page]]];
    self.imgView = img;
    [self.view addSubview:imgView];
    [img release];
    
    [imgView setImage:[UIImage imageNamed:[imageData.imgArray objectAtIndex:Page]]];
    self.title = [NSString stringWithFormat:@"image %@",[imageData.imgArray objectAtIndex:Page]];
    
    self.Timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(PlayPage:) userInfo:nil repeats:NO];
}

-(void)PlayPage:(NSTimer *)timer{
    if(Page < [imageData.imgArray count] - 1)
    {
        Page ++;
        [self performSelector:@selector(Animaiton) withObject:nil afterDelay:0.1];//动画转页效果
    }else if(Page == [imageData.imgArray count] - 1){
        [Timer invalidate];
        TheEndAlert = [[UIAlertView alloc] initWithTitle:@""
                                                 message:@"The end!"
                                                delegate:self 
                                       cancelButtonTitle:nil 
                                       otherButtonTitles:nil];
        [TheEndAlert show];
        [self performSelector:@selector(endAlertViewDismiss) withObject:nil afterDelay:1.0];
    }

}
 


/*=======================================================
翻页动画
========================================================*/
-(void)Animaiton{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    self.title = [NSString stringWithFormat:@"image %@",[imageData.imgArray objectAtIndex:Page]];
    [imgView setImage:[UIImage imageNamed:[imageData.imgArray objectAtIndex:Page]]];
    [UIView commitAnimations];
    self.Timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(PlayPage:) userInfo:nil repeats:NO];
}
 

/*=======================================================
AlertView消失
========================================================*/
-(void)endAlertViewDismiss{
    [TheEndAlert dismissWithClickedButtonIndex:0 animated:NO];
    [TheEndAlert release];
    TheEndAlert = NULL;
}
 

你可能感兴趣的:(html,PHP,cache,bbs)