简体   繁体   English

在同一视图控制器内的图像之间滑动

[英]swiping between images within the same view controller

I'm new to swift but have android experience. 我是新手,但是有Android经验。 Is there a iOS control similar to the android viewpager? 是否有一个类似于android viewpager的iOS控件? I'm creating an app that has a view controller that contains a large image view and several text fields. 我正在创建一个包含视图控制器的应用程序,其中包含大型图像视图和几个文本字段。 The image view covers half the screen or more and the text fields take up the rest of the screen. 图像视图覆盖屏幕的一半或更多,文本字段占据屏幕的其余部分。 I need to swipe between images while the text stays in place. 我需要在文字保持原位的同时在图片之间滑动。 What's the best way to implement this? 实现此目的的最佳方法是什么? I thought of adding swipe gesture recognizer and changing the image on swipe but is that the best way? 我想添加滑动手势识别器并更改滑动图像,但这是最好的方法吗?

You can use UIPageControl. 您可以使用UIPageControl。 It has capability to swipe between pages(ie page with image and text) 它具有在页面之间滑动的功能(即带有图像和文本的页面)

You can use a Pageview controller, if you're using a storyboard. 如果您使用的是故事板,则可以使用Pageview控制器。

  1. Drag a pageviewcontroller into your storyboard 将pageviewcontroller拖到情节提要中
  2. On your main view controller, drag a container view and CTRL + DRAG from your container view towards your pageviewcontroller and choose Embed 在主视图控制器上,将容器视图和CTRL + DRAG从容器视图拖向pageviewController,然后选择“ 嵌入”
  3. Now on your pageviewController define your controllers, for each image make one viewcontroller. 现在在您的pageviewController上定义您的控制器,为每个图像创建一个viewcontroller。 So for example if you have 3 images, make 3 viewcontrollers for each. 因此,例如,如果您有3张图像,则为每个图像制作3个视图控制器。 this is the simplest you can do. 这是最简单的方法。
  4. Other option would be using CollectionView 其他选项将使用CollectionView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 快速在视图控制器之间滑动 - Swiping between View Controllers in swift 使用页面视图 Controller 在视图之间滑动时防止视图控制器更新 - Prevent view controllers from updating when swiping between views with a Page View Controller iOS暂时禁用页面视图控制器刷卡 - iOS temporarily disable Page View Controller swiping 在同一视图控制器类之间传递数据 - Pass data between same view controller class 在同一个类的两个视图控制器之间导航? - Navigating between two view controller of the same class? 在视图控制器之间拖放(包含在同一视图控制器中) - Drag & drop between view controllers (contained in the same view controller) 当通过向下滑动关闭 iOS 中的查看 controller 时如何运行代码? - How to run code when view controller in iOS is dismissed by swiping down? 如何停止手势滑动回上一个视图控制器? - How to stop gesture swiping back to previous view controller? 无法触发同一视图上 2 个图像的点击手势标识符 Controller - Unable to trigger Tap Gesture Identifier for 2 Images on the same View Controller 在 Swift 中使用 imagePickerController 在同一个视图控制器中选择两个不同的图像 - Picking two different images in the same view controller using imagePickerController in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM