Questions tagged [uikit-dynamics]

UIKit Dynamics is a feature introduced in iOS 7 that enables dynamic behaviors, which offers a way to enhance the user experience by incorporating real-world behaviors and characteristics, such as gravity, into your animations.

UIKit Dynamics is "a composable, reusable, declarative, real-world inspired animation, and interaction system" (as described in WWDC 2013 video, Getting Started with UIKit Dynamics).

Any object that conforms to the UIDynamicItem protocol, such as UIView objects, can be associated with "behaviors" that can be added to a dynamic animator, a UIDynamicAnimator. These behaviors include forces, elasticity, gravity, collisions, etc.

The types of behavior objects which can be added to the UIDynamicAnimator object include UIAttachmentBehavior, UICollisionBehavior, UIDynamicItemBehavior, UIGravityBehavior, UIPushBehavior, and UISnapBehavior. You can also combine these behaviors together or create your own custom dynamic behaviors.

UIKit Dynamics is not designed to replace Core Animation or UIView animations, but is designed to offer another mechanism to easily create more interactive and dynamic animations with less code. Likewise, UIKit Dynamics is not intended to replace SpriteKit, which might be better suited for many games.

Resources:

Related tags:

203 questions
1
vote
1 answer

How to re-draw line connected between moveable two UIView

I would like to re-draw the line between two movable UIView, depending on the position of UIView. So I found this. However, this method uses "Pan Gesture" to re-draw lines, depending on the position of the gesture. Also found are setNeedsDisplay(),…
bakuiseok
  • 41
  • 1
  • 10
1
vote
0 answers

UIDynamicItemBehavior.density not affecting object physics in UIFieldBehavior?

I'm learning about the UIDynamicAnimator (very cool!) and have set up a test project. I've got things working but it doesn't appear that the density of my objects is taken into account in the physics of the UIFieldBehavior.linearGravityField(_:).…
Brian M
  • 3,812
  • 2
  • 11
  • 31
1
vote
1 answer

Adding more than 32 UIFieldBehaviors to a UIDynamicAnimator causes a SIGABRT

I have the following code. When I iterate 25 times (5 * 5), it works fine. When I iterate 36 times (6 * 6 in the for loops), it crashes with SIGABRT. I've pasted an image of the error (Playgrounds in Xcode won't let me copy paste it). Is this an…
Tom H
  • 1,316
  • 14
  • 26
1
vote
0 answers

Modify gravity of certain items of all items in UIGravityBehavior

How can we customize the gravity of each item of UIGravityBehavior, like: gravity.gravityDirection.dy = 0.7 ( for some items ) gravity.gravityDirection.dy = 0.3 ( for others) my code is: gravity = UIGravityBehavior(items:…
Hassan Taleb
  • 2,350
  • 2
  • 19
  • 24
1
vote
1 answer

How to pause and resume UIDynamicAnimator physics simulation

How would you go about pausing and resuming a UIDynamicAnimator's physics simulation? There is no way to programmatically pause and resume. There is a "paused" state when all items are at rest however I am am looking for something different. For…
1
vote
1 answer

UIDynamicAnimator items(in:) crashes in iOS 11

In iOS 11 (Xcode 9 beta 5), I'm calling UIDynamicAnimator's items(in:) method and immediately crashing: NSArray element failed to match the Swift Array Element type What's going on?
matt
  • 515,959
  • 87
  • 875
  • 1,141
1
vote
1 answer

View Transition where view has constraints

I am creating a custom view transition where the view controller being presented swings down, using a UIDynamicAnimator. The animation works in swinging the entire view down, except when I move the toView up off the screen in preparation for…
mginn
  • 16,036
  • 4
  • 26
  • 54
1
vote
2 answers

Is it possible to simulate gravity to an object / UIView in UIDynamicKit?

Without using SpriteKit, is it possible to simulate gravity for UIView object? What I'm trying to achieve is a center UIView with other object floating around it. Almost like planets around a Sun. And also have it attract and repulse from the…
Tuan Anh Vu
  • 760
  • 1
  • 7
  • 26
1
vote
0 answers

UIDynamics for heatmap

For a customer I need to realize a UIView which should resemble this one: To be screen My idea was to use UIDynamics and some sort of UIFieldBehaviour. So I created a container view containerView, added a bunch of UIViews. Those internal views are…
Diego Viganò
  • 163
  • 1
  • 10
1
vote
0 answers

UISnapBehavior Animation Glitch

When using UISnapBehavior to reset a view to the center of the screen I get the expected bounce effect. But after scrolling a UIScrollView that is a subview of the view being snapped the UISnapBehavior dampening seems to have a different base…
wasabi
  • 1,110
  • 10
  • 23
1
vote
1 answer

UIFieldBehaviour for snapping dynamic view to top, bottom or middle of screen

I'm using a draggable view which is the width and height of the screen and can be moved up or down on the screen depending on the pan gesture. When the pan gesture has ended I want it to snap to three different y positions, top, middle or bottom…
1
vote
1 answer

How to create realistic ball drop from cliff using swift and UIkit

I try to make the ball with realistic physics when it fall from cliff, as you can see in in image 2. that's what I what to achieve, for now I have what is drawn in image 1. for image 1. I use this code: ball.center.x += 5 ball.center.y -= 4 By the…
artG
  • 235
  • 3
  • 12
1
vote
3 answers

Swift - Round Button

I want to create several round buttons in swift, with collision detection and gravity acting on them. But whenever I do so, during collision they acts as a square, (I've tried adding image to button or by creating it through code but the result…
1
vote
0 answers

Change Image Item after Motion Shake and Collision Detected in in UIDynamics Swift

I have the following code and I want to show an alert and change the image after the collision and based on a random number generated. However, it shows the result before the collision... Any idea??? import UIKit class ViewController:…
Alexandros
  • 11
  • 2
1
vote
1 answer

What's the proper way to add UIKit Dynamics to UICollectionViewCells?

I'm trying to use UIKit Dynamics to implement swipe-to-delete on my UICollectionViewCells. Things aren't going as planned, though. Here's the code in UICollectionViewCell's awakeFromNib method: self.animator = [[UIDynamicAnimator alloc]…