我一直在努力尝试让 UIImageView 在 UIScrollView 滚动时更改其图像,有点像 Photos.app。
这是我的代码:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.x > 296){
self.currentDBNum++;
self.currentDoorbell = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[[self.doorbells objectAtIndex:currentDBNum] objectForKey:@"Image"] ofType:@"jpg"]];
self.doorbellPic.image = currentDoorbell;
self.currentSoundPath = [[NSBundle mainBundle] pathForResource:[[doorbells objectAtIndex:currentDBNum] objectForKey:@"Sound"] ofType:@"caf"];
}
}
有什么提示吗?谢谢。 (图像的宽度为 296。)
最佳答案
有两种方法可以完成您的任务:
- 尝试学习T hree20 TTPhotoViewController这将与您在 iPhone 中看到的 photo.app 完全相同。
- 如果你想自己做,那么根据我的经验,你必须将多个具有正确位置(x,y,宽度,高度)的 UIImageView 添加到 UIScrollView 中。请记住使用正确的内容大小初始化 ScrollView ,以便它可以滚动。一个例子:image1是(0,0,320,480),image2是(320,0,320,480),image3是(640,0,320,480),等等...那么你的 ScrollView 内容大小将是最后一项的x值+宽度最后一项。
关于iphone - 如何制作 UIScrollView 图片库? (iPhone SDK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2291963/