{"id":5641,"date":"2014-04-04T15:16:37","date_gmt":"2014-04-04T15:16:37","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/04\/uikit-dynamics-issue-with-referencing-the-uidynamicanimator-from-childviewcontroller-collection-of-common-programming-errors\/"},"modified":"2014-04-04T15:16:37","modified_gmt":"2014-04-04T15:16:37","slug":"uikit-dynamics-issue-with-referencing-the-uidynamicanimator-from-childviewcontroller-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/04\/uikit-dynamics-issue-with-referencing-the-uidynamicanimator-from-childviewcontroller-collection-of-common-programming-errors\/","title":{"rendered":"UIKit Dynamics &#8211; Issue with referencing the UIDynamicAnimator from ChildViewController-Collection of common programming errors"},"content":{"rendered":"<p>I have one UIViewController <em>container<\/em> with contains multiple UIViewController <em>boxes<\/em>. I&#8217;d like to apply physics behaviour to the boxes using UIKit Dynamics. The container defines the outer border.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/NcCoU.png\" \/><\/p>\n<p>The <strong>UIDynamicAnimator<\/strong> is an object in the container and all Dynamics behaviours are part of the boxes.<\/p>\n<p>Problem: I run into error messages when I reference the animator from the boxes (childviewcontrollers) for adding the box behaviours.<\/p>\n<p>Here&#8217;s the error message<\/p>\n<pre><code>&gt; Terminating app due to uncaught exception\n&gt; 'NSInvalidArgumentException', reason: 'View item ( frame = (0 568; 120 40); clipsToBounds = YES; autoresize = W+H;\n&gt; gestureRecognizers = ; layer =  0x9972780&gt;&gt;) should be a descendant of reference view in\n&gt;  Stopped (0.000000s) in  0x9916bf0&gt; {{0, 0}, {320, 568}}'\n<\/code><\/pre>\n<p><strong>UIViewController Container<\/strong><\/p>\n<pre><code>- (void)viewDidLoad\n{\n    [super viewDidLoad];\n\n    UIDynamicAnimator* animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];\n    _animator = animator;\n...\n}\n<\/code><\/pre>\n<p>Adding Boxes as Subviews and ChildViewControllers<\/p>\n<pre><code>- (void)tapOnContainer:(UITapGestureRecognizer*)touch {\n...\n            BoxViewController *note = [[BoxViewController alloc]init];\n            [box setContainerObject:self];\n            [self addChildViewController:box];\n            [self.view addSubview:box.view];\n}\n<\/code><\/pre>\n<p><strong>UIViewController Box<\/strong><\/p>\n<pre><code>- (void)viewDidLoad\n{\n    _containerViewController = (ViewController*) self.parentViewController;\n    _gravityBehaviour = [[UIGravityBehavior alloc]initWithItems:@[self.view]];\n    [_containerViewController.animator addBehavior:_gravityBehaviour];\n...\n}\n<\/code><\/pre>\n<p>Any idea how to get this working? Is it okay to split the UIDynamicAnimator and the UIDynamicBehavior objects like this?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have one UIViewController container with contains multiple UIViewController boxes. I&#8217;d like to apply physics behaviour to the boxes using UIKit Dynamics. The container defines the outer border. The UIDynamicAnimator is an object in the container and all Dynamics behaviours are part of the boxes. Problem: I run into error messages when I reference the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5641","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5641"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5641\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}