0
votes

i have a scollview and i want to display suppose 10 images. frame width is 320 for iphone and 768 for ipad. something like this image enter image description here

middle image will be our current selection(mountain image according to this snapshot). Now i want to scroll left or right to check all the images. If waterfall is at position 1 mountain at position 2 and hut at position 3, when i scroll right i want to show mountain at position 1 hut at position2 and a new image at position 3.

PLZ tell me how to do this

3

3 Answers

0
votes

You have to adjust and set the contentOffset of the scrollView based on the size of the image. You must also set the necessary contentSize for the scrollView which will enable the scrolling.

0
votes

hey use content offset.

and use this code u get what you want.
this is a scrollview for two image at a time seen on iPhone and when a image scroll at middle of iPhone the label set midlle image label.. as you set width 320 change to 320

-(void)scrollViewDidScroll:(UIScrollView *)inscrollView{

p = scrollView.contentOffset;

NSLog(@"x = %f, y = %f", p.x, p.y);

[self loadDescLbl]; 
}  

-(void)loadDescLbl {

int point;
point = p.x+160;
    int i;
    i = point / 160;
    i = i-1;
if(i > fetArray.count-1){
        i = fetArray.count -1;
    }
if(i == -1)
{
    i = 0;
}
imageView[i].highlighted = YES;
    if([yourArray objectAtIndex:i] isEqualToString:@""]){
        priceLbl.text = @"";
    }
    else {
        priceLbl.text = [NSString stringWithFormat:@"%@", [yourArray objectAtIndex:i]];
    }   
    [scroll addSubview:priceLbl];

// }

}

just set point = p.x and i = point;

if you get problem then tell me...

0
votes

f all of your images are of the same size you could add 2 buttons (left right) ... and when you tap one of them change the content offset's frame with the width of one picture ... if you don't want buttons you can obtain the same effect with UISwipeGestureRecognizer

-(IBAction)changeVisibleRect:(UIButton *)btn {

[UIView beginAnimation:@"animation name" context:nil];
[UIView setAnimationDuration:0.3];  //or how much you want in seconds

[scrollview.contentOffset setFrame:CGRectMake(pictureSize * i, 0, pictureSizeWidth, pictureSizeHeight)]; //i = the number of the picture 

[UIView commitAnimations];

}

CGRectMake(pictureSize * i, 0, pictureSizeWidth, pictureSizeHeight)] ... instead of pictureSize * i ... you could asign you left or right buttons tags and ... make a

if(btn.tag == 1) {
[UIView beginAnimation:@"animation name" context:nil];
[UIView setAnimationDuration:0.3];  //or how much you want in seconds

[scrollview.contentOffset setFrame:CGRectMake(scrollView.contentOffset.frame.origin.x - pictureSizeWidth, 0, pictureSizeWidth, pictureSizeHeight)]; //i = the number of the picture 

[UIView commitAnimations];
}

assuming your left button has set tag = 1;

for the SwipeGesture it would be the same animation code / idea