Kodeco Forums

Video Tutorial: Intro to Auto Layout Part 3: Editing Constraints

Learn about editing constraints in Auto Layout.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3201-auto-layout/lessons/4

I feel like the challenge is 100x harder than the demo. There are a lot things uncovered in the demo like how to make the each image recognize touch, the aspect ratio, and moreā€¦ The challenge should be something that was covered in the demo to increase confidence to complete the challenge.

Hi couple of questions

  1. How to create the tapGestures?
  2. Why did you choose ā€˜Outlet Connectionsā€™ for constraints rather than ā€˜Outletā€™?

Sorry about that. The challenges are designed to cover the topic from the demoā€¦ with a little bit more. If this one was too big of a leap, Iā€™m sorry. I appreciate the feedback and Iā€™ll try to do better in future tutorials.

If you have specific questions, Iā€™m happy to answer those as well. In any case, thanks for helping me make these tutorials better.

  1. Tap Gesture Recognizers can be dragged from the Object library (in the lower right corner of Interface Builder) onto the view they should target.

  2. In the code, the imageTapped method should act on the appropriate constraint. There are a couple of ways to accomplish this, one would be to have a method for each image and an outlet for each constraint. But in this case, we use a collection and a tag as an index into the collection. The way to make several objects in Interface Builder connect to the same collection is using the ā€œOutlet Collectionā€.

Hey, have question
I tried to make a challenge but taps dont works, what could be the reason?

Make sure user interaction is enabled (step 5) and make sure the tap gesture is attached to the image and connected to the IBAction.

Thanks, interaction is was off

Hi,

The demo video was useful. Just one suggestion. I have also completed the stack view course. I felt that the idea of covering the solution of challenge in a video is very easy compared to being on a pdf.
Is this something that you would be able to do in future?
Thanks.

sender.view?.tag is 0 irrespective of the imageView i tap on. Iā€™m not sure where iā€™m going wrong. Any suggestions?

Hi, great tutorial thus far. Iā€™m doing the challenge app right now. Iā€™m using Xcode 7.3.1 and when creating the outlet collection for my first constraint everything works well. However, Xcode seemingly does not allow me to attach more constraints to the outlet collection regardless of where on the outlet text I highlight. How can I fix this?

Update: Same with the tapGesture and the associated imageTapped function. For some reason Iā€™m not able to connect multiple views to one IBAction or IBOutlet.

Update 2: Creating a new sample project Iā€™m able to connect multiple views/tap gesture recognizers to single IBAction/Outlets. I suppose for the challenge app there is something strange going on beneath the hood.

Steps 6-9 have you set the tag of the image views to 1, 2, 3, and 4. Have you set those in Interface Builder? The tag property can be seen on the attributes inspector under the ā€œViewā€ section.

Hm, Iā€™m not having any issues creating outlets, but I have seen various issues before with Xcode creating outlets. Usually, if I try again it works, or maybe restart Xcode. The other thing you can try is using a different method to create the outlet. The Connections Inspector has circles you can drag or you can right-click on the constraint and drag from ā€œNew Referencing Outlet Collectionā€ for the constraint or ā€œSelectorā€ for the gesture recognizer to the View Controller in the view hierarchy and pick the connection.

cant understand how this works.