简体   繁体   中英

swiping between images within the same view controller

I'm new to swift but have android experience. Is there a iOS control similar to the android viewpager? 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. 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.

  1. Drag a pageviewcontroller into your storyboard
  2. On your main view controller, drag a container view and CTRL + DRAG from your container view towards your pageviewcontroller and choose Embed
  3. Now on your pageviewController define your controllers, for each image make one viewcontroller. So for example if you have 3 images, make 3 viewcontrollers for each. this is the simplest you can do.
  4. Other option would be using CollectionView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM