0

I am trying to create an iPhone app where you swipe right or left to get from one view to another. I know how to do it from scratch with my own code, but I want to learn the Apple way of doing it, which means drag and drop the UISwipeGestureRecognizer icon into the storyboard and change settings in some way. I can get it to have a sideway swipe, but not with the views appearing from the sides. Only have the view appear from the default bottom.

So frustrating not coding from scratch, don't know where the problem is. Help very much appreciated!

Adremalin
  • 137
  • 3
  • 9

1 Answers1

1

I don't think you are clear on whether you are trying to have "views" appear from the sides or "view controllers" appear from the sides. There is a distinction. What you wish to do in general is drag a swipe gesture recognizer and drop it onto the view you wish to recognize the gesture (for example the top level view of the scene). Then you need to control drag the gesture from the top of the scene to the code and create an action method. Within that action method, you can perform a segue to another view controller, if you wish to transition to an entirely new scene. Otherwise, you can initialize another view and animate it onto the screen.

SwiftMatt
  • 949
  • 1
  • 9
  • 19
  • In that case, what you are referring to is called a "segue." There are a limited amount of segues that are provided for you to use. Among them are push and pop segues which are now known as "show" segues. These segues will cause a view controller to appear from the right if you are pushing and cause the previous view controller to appear from the left if you are popping. You could also implement a custom segue by subclassing UIStoryboardSegue – SwiftMatt Dec 31 '15 at 09:37
  • Thanks for the input on distinction! I want the View including its View Controller to appear from the side. Aah, I think I know what you mean, testing it! Performing a segue to another view controller; does that mean I should code in the View Controller's code I am in and create a function to activate the View Controller of which view I am swiping to? – Adremalin Dec 31 '15 at 09:42
  • What you can do is drag a swipe gesture recognizer onto the view. Then you can control-drag from the gesture recognizer itself onto a new scene and use a "show" segue or a custom segue which you give an identifier in the identity inspector and trigger in code. – SwiftMatt Dec 31 '15 at 10:07
  • 1
    It works! I switched from "modal" to "show detail" and just deselected "animate" so the new view doesn't appear from the bottom. It seams like "popover" is deprecated in the new version of Xcode. Do you know if there are any restraints on the "show detail" (or show segues)? Can I for example build as much in the swiped views as the "original/initialized" one? – Adremalin Dec 31 '15 at 10:26