Beginning iOS Animations · Animating Constraint Constants |

This is a companion discussion topic for the original entry at
1 Like

Hi Catie! How’s it going?

I hope you are well. I have been following this video series. I’m following each instruction and literally pausing the video every ten seconds to make sure I understand each step.

In lesson two after we add the following line I get an error. My animation doesn’t work :frowning:

menuHeightConstraint.constant = menuIsOpen ? 200 : 80

I’d like to know where I went wrong or if there was a source error contained in the start directory from the resources folder.

I get the following output from my console and an error in the AppDelegate file on line 36

2018-11-05 10:35:20.061618-0500 PackingList[38783:6148120] -[UIView setConstant:]: unrecognized selector sent to instance 0x7fc4dd408750
2018-11-05 10:35:20.066570-0500 PackingList[38783:6148120] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UIView setConstant:]: unrecognized selector sent to instance 0x7fc4dd408750’
*** First throw call stack:
0 CoreFoundation 0x000000010f69629b __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010d4b5735 objc_exception_throw + 48
2 CoreFoundation 0x000000010f6b4fa4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKitCore 0x0000000113201163 -[UIResponder doesNotRecognizeSelector:] + 287
4 CoreFoundation 0x000000010f69afb6 forwarding + 1446
5 CoreFoundation 0x000000010f69ce88 _CF_forwarding_prep_0 + 120
6 PackingList 0x000000010cb8618d $S11PackingList14ViewControllerC10toggleMenuyyyXlF + 333
7 PackingList 0x000000010cb861ec $S11PackingList14ViewControllerC10toggleMenuyyyXlFTo + 60
8 UIKitCore 0x0000000112e1b7c3 -[UIApplication sendAction:to:from:forEvent:] + 83
9 UIKitCore 0x0000000112f53e85 -[UIControl sendAction:to:forEvent:] + 67
10 UIKitCore 0x0000000112f541a2 -[UIControl _sendActionsForEvents:withEvent:] + 450
11 UIKitCore 0x0000000112f530e6 -[UIControl touchesEnded:withEvent:] + 583
12 UIKitCore 0x000000011362e334 -[UIWindow _sendTouchesForEvent:] + 2729
13 UIKitCore 0x000000011362fa30 -[UIWindow sendEvent:] + 4080
14 UIKitCore 0x0000000112e35e10 -[UIApplication sendEvent:] + 352
15 UIKitCore 0x0000000112d6e0d0 __dispatchPreprocessedEventFromEventQueue + 3024
16 UIKitCore 0x0000000112d70cf2 __handleEventQueueInternal + 5948
17 CoreFoundation 0x000000010f5f9b31 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
18 CoreFoundation 0x000000010f5f93a3 __CFRunLoopDoSources0 + 243
19 CoreFoundation 0x000000010f5f3a4f __CFRunLoopRun + 1263
20 CoreFoundation 0x000000010f5f3221 CFRunLoopRunSpecific + 625
21 GraphicsServices 0x0000000116fe31dd GSEventRunModal + 62
22 UIKitCore 0x0000000112e1a115 UIApplicationMain + 140
23 PackingList 0x000000010cb88dc4 main + 68
24 libdyld.dylib 0x0000000110b21551 start + 1
libc++abi.dylib: terminating with uncaught exception of type NSException

@mazurick Make sure you have properly connected your constraint in the storyboard to your menuHeightConstraint outlet in the view controller. I hope it helps!

Hello @shogunkaramazov!

Thank you! It works!

I found my error too and learned where I was going wrong. I think my error was that I had not correctly selected my constraint for the menus height when I dragged from new referencing outlet to the yellow view controller object and selected menuHeightConstraint.

This really made my day. Until recently I was a rockstar prototyper with Framer. When Framer.js changed to react I found myself confronted with learning a new language just to prototype. I practice swift and Xcode and figured, hey, maybe I can prototype interactions on iOS. So this is my first step towards that goal and it’s looks promising.

1 Like

Hi @catie, quick question: How is changing the height constraint on the menu revealing the horizontal slider? I do not see the slider in the interface builder, and the toggleMenu method does not appear to run any additional code for inserting this slider. I know this isn’t the point of the lesson, but I’m hoping you can shed some light on how this was achieved.

Hi! Thanks very much for your question. Honestly, I’ve updated this course several times now and each time I’ve reconsidered how much to hide the slider implementation. We’ll see what we can do in the next update to make it less mysterious.

I expect part of the reason it wasn’t easy to find is that the class for the slider is actually called “HorizontalItemList”! You can find it in HorizontalItemList.swift. In ViewController.swift, the makeSlider() method is where the slider is actually initialized and added to its parent view. makeSlider() is called in viewDidLoad(). So, the slider is already added by the time you’re seeing the view controller, but it’s hidden behind the table view. I see you have another question related to this, so I’ll talk more about what I mean by “hidden” there.

If you are wondering how the size or position are determined, take a look at the HorizontalItemList class. You’ll see the convenience initializer uses a predefined CGRect to size and position the slider. The position and height are always the same, but the width varies depending on the view you pass in at initialization.

@catie, Thanks for taking the time to explain!

1 Like

Thank you! Helpful information for iOS developers.

@smartym_pro Really glad you like it! :]

@catie, @jessycatterwaul, please describe UIView.animate a bit more detailed:

  1. What object does this method belongs to in current application? VIewController or _ sender: AnyObject or…?
  2. What is view in view.layoutIfNeeded?

Also please explain why does position of view.layoutIfNeeded in toggleMenu() matter?


1 - It’s a class method on UIView! So, it belongs to the UIView class, and not to a particular object in the application.

2 - view is the root view of the ViewController instance.

1 Like

thank you very much! everything is clear now! :slightly_smiling_face:

1 Like