Minestrone-Soup
Minestrone-Soup

Reputation: 399

Can a dynamic object be a UIImageView

I have a UIDynamicAnimator with behaviour: UIPushBehaviour. I know the UIView objects can become a dynamic object with initWithReferenceView. But is it possible for a dynamic object to be a UIImageView. And if so, how?

(I have read the apple developer documents and I can't really grasp the UIDynamicAnimator concepts, so forgive me if this is stupid)

Upvotes: 2

Views: 275

Answers (1)

Rob Napier
Rob Napier

Reputation: 299265

Nothing ever "becomes a dynamic object." That's not the way to think about it. A dynamic animator has behaviors. Behaviors have items. A view can be an item. So that means that UIDynamicAnimator can animate a UIImageView. The view has no idea that it's being animated. It just gets setCenter: called on it repeatedly (and as @Rob notes below, also setTransform: and bounds). There's no difference here between an image view and any other kind of view.

The key to understand is that UIKit Dynamics is completely backwards. In UIView animations and in Core Animation, the view is pretty intimately involved in being animated. You can ask a view for its animations, add and remove them, etc. But UIKit Dynamics is glued on and works entirely from outside the view. You cannot ask a view if it is being managed by UIKit Dynamics. You can only ask UIKit Dynamics what views it is messing with (and you can't always easily ask that).

In my experience, UIKit Dynamics can work reasonably if your animations are extremely simple. But if things are complex at all, you probably need to do it by hand with Core Animation (or SpriteKit, depending on your need). There is also very little documentation for it. Oh, and the various behaviors have very inconsistent APIs. It's not my favorite framework in Cocoa...

If you want to see some examples of this, you may want to pull down the sample code from iOS 7:PTL (iosptl.com) Chapter 19. It includes putting push animators onto views.

Upvotes: 2

Related Questions