2

Is there a simple way to handle the resizing of a UIView controlled by UIKit Dynamics? I am aware of UIDynamicAnimator's updateItemUsingCurrentState: method, but the documentation seems to point out that this is for position and rotation changes only. When I call this method after a bounds change, the physical model continues to work as if the size hasn't changed.

This is for a fairly simple UI scenario: a UIView containing a UILabel with text that changes depending on user input and can grow/shrink slightly (think of a callout view on a map), with a UICollisionBehavior to keep inside its superview and a UISnapBehavior to animate its placement.

I realise that size changes aren't so simple in a physical model, but given that it's quite common in UI scenarios and that UIKit Dynamics appears to handle screen orientation changes automagically, I'm hoping there is support for it.

Clafou
  • 15,250
  • 7
  • 58
  • 89
  • It's a bit unclear what you want to achieve. Which items are controlled by UIKit Dynamics? Which view do you want to resize and when? Maybe some sample code would make things more clear. – Michał Ciuba Dec 04 '14 at 15:16
  • Sorry! I clarified (removed "dynamic text", I meant text that changes, not dynamic behaviour). Think of a map annotation that is animated with UIKit Dynamics, and the frame of the annotation sometimes grows to accommodate more text. – Clafou Dec 04 '14 at 15:24
  • I can resize the UIView, but then the UICollisionBehavior still uses the old size, so the bigger UIView can then extend beyond its superview's frame. – Clafou Dec 04 '14 at 15:31
  • According to this answer http://stackoverflow.com/a/20985033/2128900 you can add a workaround: remove a behavior and add it again. It's not a perfect solution, though. Consider filling a radar if you think `UIDynamicAnimator` should react properly to a bounds change. – Michał Ciuba Dec 04 '14 at 15:49
  • Great, I can confirm that removing all behaviors (not just the UICollisionBehavior it seems) worked. Thanks! I'll accept if you post as an answer. – Clafou Dec 04 '14 at 16:29
  • 1
    I've just linked to an another answer, I'm not sure if I should receive credits for that :) – Michał Ciuba Dec 04 '14 at 16:30

0 Answers0