如何在 viewController 中显示与下面的屏幕截图相同的图像?
在我的 iPad 程序中,我有一个保存图像的数组。如何在 viewController 中显示所有图像(来自图像数组),与下面的屏幕截图相同?有没有好的方法可以参考,有任何示例应用程序路径或示例代码吗?
我需要以下功能。
- 点击图像将全屏显示它
- 关闭按钮可关闭此视图,与屏幕截图相同。
- 两个按钮用于显示剩余图像和先前图像。
下面附有示例屏幕截图。我们可以看到下面的应用程序在屏幕右侧显示所有图像。
In my iPad program I have an array which holds images. How can I display my all images (from an image array) in my viewController the same as the below screen shot? Is there a good way to do it, any sample application paths to refer or sample code?
I need the following functionality.
- Tapping an image will show it full screen
- A close button to close this view as the same as the screen shot.
- Two buttons to display the remaining and previous images.
A sample screen shot is attached below. We can see that the below application is showing all images at the right side of the screen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这应该很容易,尽管需要一些编码。
从简单的基于视图应用模板开始。
我不知道图像来自哪里,所以我只是将所有要显示的图像放在资源文件夹中。
视图控制器
PictureViewController
将接受 UIImage 数组,并应以模态方式呈现。我将在下面发布代码。显示
PictureViewController
的代码放置在模板创建的视图控制器中。我刚刚向视图添加了一个简单的 UIButton 以触发如下所示的操作:视图控制器的视图是使用界面生成器创建的,如下所示:
PictureViewController.xib
查看层次结构
全屏图像链接到以下头文件中看到的插座
fullScreenImage
。动作也相互关联。我已将全屏 imageView 的内容模式设置为 Aspect Fit。
缩略图将通过代码动态添加。下面是视图控制器的代码
PictureViewController.h
PictureViewController.m
顶部的定义
MAX_THUMBNAILS
定义了所看到的缩略图的最大数量。UITapGestureRecognizer
将处理缩略图的点击事件。调整setupThumbnailImageViews
中的CGRectMake
以根据需要放置缩略图。该控制器只是一种基本方法,没有方向支持。结果:
Alright, this should be easy, though a bit of coding is needed.
Start out with a simple view based app template.
I don't know where the images come from so I just put all the images to be shown in the resources folder.
The view controller
PictureViewController
will accept an array of UIImages and should be presented modally. I'll post the code below.The code to show the
PictureViewController
is placed in the view controller created by the template. I just added a simple UIButton to the view to trigger an action which looks something like this:The view controller's view was created with interface builder, looking like this:
PictureViewController.xib
View Hierarchy
The fullscreen image is linked to an outlet
fullScreenImage
seen in the following header file. Actions are connected as well.I've set the fullscreen imageView's content mode to Aspect Fit.
The Thumbnails will be added dynamically with code. Here's the view controller's code
PictureViewController.h
PictureViewController.m
The define
MAX_THUMBNAILS
on top defines the maximum of thumbnails seen. AUITapGestureRecognizer
will take care of the tap events for the thumbnails. Adjust theCGRectMake
insetupThumbnailImageViews
to position the thumbnails as you wish. This controller is just a basic approach without orientation support.The result: