Hi I am also a new bee and Im reading this book so far my code works fine but only two images are displaying the first image then continuously second image I tried an NSLog statement of the tempImageView.tag its 0 it doesn't change to any other value please help my code :
Code:
- (void)viewDidLoad
{
//init the first image view
[imageView1 setImage:[UIImage imageNamed:@"img1.jpeg"]];
tempImageView = imageView2;
//make the first image view visible and hide the second
[imageView1 setHidden:NO];
[imageView2 setHidden:YES];
//add event handler for the page control
[pageControl addTarget:self
action:@selector(pageTurning:)
forControlEvents:UIControlEventValueChanged];
prevPage = 0;
[super viewDidLoad];
}
//when the page controller's value is changed
-(void) pageTurning: (UIPageControl *)pageController{
//get the page number you can turnning to
NSInteger nextPage = [pageController currentPage];
switch (nextPage){
case 0:
[tempImageView setImage:
[UIImage imageNamed:@"img1.jpeg"]];
break;
case 1:
[tempImageView setImage:
[UIImage imageNamed:@"img2.jpeg"]];
break;
case 2:
[tempImageView setImage:
[UIImage imageNamed:@"img3.jpeg"]];
break;
case 3:
[tempImageView setImage:
[UIImage imageNamed:@"img4.jpeg"]];
break;
case 4:
[tempImageView setImage:
[UIImage imageNamed:@"img5.jpeg"]];
break;
default:
break;
}
//switch the two imageviews
if(tempImageView.tag == 0){
tempImageView = imageView1;
bgImageView = imageView2 ;
}
else{
tempImageView = imageView2;
bgImageView = imageView1 ;
}
UIViewAnimationOptions transitionOption;
if(nextPage > prevPage)
//--if moving from left to right
transitionOption = UIViewAnimationOptionTransitionFlipFromLeft;
else {
//--if moving from right to left
transitionOption = UIViewAnimationOptionTransitionFlipFromRight;
}
//---animate by flipping the imagees---
[UIView transitionWithView:tempImageView
duration:2.5
options:(transitionOption)
animations:^{
[tempImageView setHidden:YES];
}
completion:NULL];
[UIView transitionWithView:bgImageView
duration:2.5
options:(transitionOption)
animations:^{
[bgImageView setHidden:NO];
}
completion:NULL];
}