我有一个scollview,我想显示假设10个图像。iphone的边框宽度为320,ipad的边框宽度为768。如下图所示

中间的图像将是我们当前的选择(根据此快照的山体图像)。现在,我想要向左或向右滚动以检查所有图像。如果瀑布在位置1,山在位置2,小屋在位置3,当我向右滚动时,我想在position2显示位置1的山和位置3的新图像。
请告诉我怎么做
发布于 2011-08-03 15:22:27
您必须根据图像的大小来调整和设置scrollView的contentOffset。您还必须为启用滚动功能的scrollView设置必要的contentSize。
发布于 2011-08-03 20:14:50
嘿,使用内容偏移。
使用这段代码你可以得到你想要的东西。
这是在iPhone上一次看到两个图像的滚动视图,当一个图像在iPhone中间滚动时,标签设置为中间图像标签。将宽度设置为320时,将更改为320
-(void)scrollViewDidScroll:(UIScrollView *)inscrollView{
p = scrollView.contentOffset;
NSLog(@"x = %f, y = %f", p.x, p.y);
[self loadDescLbl];
} -(空)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];// }
}
只需设置point = p.x和i= point;
如果你有问题告诉我..。
发布于 2011-08-03 20:17:47
如果你所有的图片都是相同大小的,你可以添加2个按钮(左右)…当你点击其中一个,改变内容偏移量的框架与一张图片的宽度...如果你不需要按钮,你可以用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)] ...而不是pictureSize *我...您可以指定您的左或右按钮标签和..。制作一个
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];
}假设你的左键设置了tag = 1;
对于SwipeGesture,它将是相同的动画代码/想法
https://stackoverflow.com/questions/6922957
复制相似问题