我正在制作一个iPhone应用程序,我需要在UIScrollView中显示一些图像,左右两侧将出现两个按钮,用户可以点击按钮,它会显示下一个或上一张图片。在底部还有一个按钮,当用户点击该按钮时,它会显示我们在scrollview中选择的图像。我想知道我们如何在该滚动视图内显示多个图像,并选择底部按钮时,如何找到哪个图像在滚动视图中。如何在iOS中的UIScrollView中显示多个图像
6
A
回答
5
从danielbeard.wordpress一个例子.COM
如果你的形象的名字不仅仅是数字:
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[scrollView setPagingEnabled:YES];
[scrollView setAlwaysBounceVertical:NO];
NSArray *imagesArray = [NSArray arrayWithObjects:@"img1.png", @"img2.png", @"img3.png", nil];
for (int i = 0; i < [imagesArray count]; i++)
{
CGFloat xOrigin = i * scrollView.frame.size.width;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, scrollView.frame.size.width, scrollView.frame.size.height)];
[imageView setImage:[UIImage imageNamed:[imagesArray objectAtIndex:i]]];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
[scrollView addSubview:imageView];
}
[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * [imagesArray count], scrollView.frame.size.height)];
2
Apple.developerPhotoScroller演示了如何使用嵌入式UIScrollViews和CATiledLayer来创建用于显示和分页可以单独摇镜和变焦照片丰富的用户体验。
CATiledLayer用于增加使用高分辨率图像或大量照片进行分页,平移和缩放的性能。
3
+0
哦......这个完全解决了这个问题和+1! –
0
你只是单纯的第一 创建的运行时间和图像的新观点,并指定标签上标记值像1000或者100和增量各方意见,然后该视图添加到滚动视图和左,右移动两个按钮,使他们的出口行为,并添加所有的滚动视图的子视图的可变数组这样
indexStart=100;
UIView *AddView=[[UIView alloc]initWithFrame:CGRectMake(55, 0, 100, 100)];
AddView.tag=indexStart;
btnTap.tag=indexStart;
UIImageView *imgview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
[AddView addSubview:imgview];
imgview.image=image;
imgview.tag=1000;
[ScrollView addSubview:AddView];
[imgArray addObject:AddView];
你用循环来做到这一点,你用这个左右键
代码,在这个代码中,editImgeView是图像视图nbetween左右键,你显示出图像,你只是简单的indexstart ++或 - 如果用户选择左边或右边按钮
for (int index = 0; index < [imgAddArrayAfter count]; index ++) {
NSLog(@"index %d",index);
UIView *vc=[imgArray objectAtIndex:index];
NSLog(@"view tag %d",vc.tag);
if(vc.tag == indexStart)
{
UIImageView *modalView=(UIImageView *) [vc viewWithTag:1000];
editImgeView.image=modalView.image;
}
}
我希望你明白;-)
0
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollView.contentSize = CGSizeMake(320, 465);
[scrollView setScrollEnabled:YES];
[scrollView setPagingEnabled:YES];
[scrollView setAlwaysBounceVertical:NO];
[self.view addSubview:scrollView];
NSMutableArray *arrImage = [NSMutableArray arrayWithObjects:@"food1.jpeg", @"food2.jpeg", @"food3.jpeg",@"food4.jpeg", @"food5.jpeg", @"food6.jpeg",@"food7.jpeg", @"food8.jpeg", @"foo9.jpeg",@"food10.jpeg", @"food11.jpeg", @"food12.jpeg",@"food13.jpeg", @"food14.jpeg", @"food15.jpeg", @"food16.jpeg", nil];
for (int i = 0; i < [arrImage count]; i++)
{
CGFloat xOrigin = i * scrollView.frame.size.width;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, scrollView.frame.size.width, scrollView.frame.size.height)];
[imageView setImage:[UIImage imageNamed:[arrImage objectAtIndex:i]]];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
[scrollView addSubview:imageView];
}
[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * [arrImage count], scrollView.frame.size.height)];
}
相关问题
- 1. 如何在ios中的uiscrollview中以gridview格式显示图像?
- 2. 在UIScrollView中显示图像
- 3. 如何在UIscrollView中显示来自URL的很多图像
- 4. 在IOS的图像视图中显示多个图像
- 5. ios如何在uitableviewcell中显示多个图像
- 6. iOS:如何在imageview中dynamiclly显示多个图像?
- 7. 如何在xcode 4.5中的UIscrollview中显示图像边框?
- 8. 如何在另一个图像中显示多个图像。
- 9. 图像显示在uiscrollview
- 10. 在IOS中显示图像
- 11. 在iOS中显示图像
- 12. 在视图中显示多个图像
- 13. 如何在iOS中显示多选图像
- 14. 如何在HTML中的多个图像上显示多个图像
- 15. 如何在iOS中的图中显示小图像
- 16. 如何在LeavesViewController的单个页面中显示多个图像?
- 17. 在UIScrollview中显示我在哪个图像swift
- 18. 嵌入在UIScrollView中的图像不会在UIPopoverController中显示
- 19. 如何正确替换iOS中UIScrollView中的UIImageView中的图像
- 20. PopOut一个中间图像在UIScrollView中包含许多图像
- 21. 在PrettyPhoto中显示多个图像
- 22. 在tabbedpane中显示多个图像
- 23. 在rails_admin中显示多个图像
- 24. 在java中显示多个图像
- 25. 检查显示在UIScrollview的图像
- 26. 显示多个UIImageView的UIScrollView
- 27. 如何在php中从数据库中显示多个图像?
- 28. 如何使用webservice在iOS中显示多个贴图注释?
- 29. 如何在inno setup的wpInstalling页面中显示多个图像
- 30. 如何在行中显示多个上传的图像
你做了什么至今 –
似乎得到了直接的代码?已经做了并且努力了吗? –