UIViewPropertyAnimator does not update the view if expected

Here is the Swift code for the playground, which I also tested in the iOS Simulator to make sure it's not a playground issue.

Setting the property fractionComplete

will change the state from inactive

to active

. However, as shown below, the view is not updated for the first two calls. Only the third call magically updates the view.

This behavior is confusing and I am looking for an explanation.

let liveView = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 50))
liveView.backgroundColor = .white

PlaygroundPage.current.needsIndefiniteExecution = true
PlaygroundPage.current.liveView = liveView

let square = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
square.backgroundColor = .red

liveView.addSubview(square)

let animator = UIViewPropertyAnimator.init(duration: 5, curve: .easeIn)

animator.addAnimations {

    square.frame.origin.x = 350
}

// State: inactive
// Does nothing, position is at 0.0
DispatchQueue.main.async {

    animator.fractionComplete = 0.5
}

// State: active
// Stil does nothing, position is at 0.0
DispatchQueue.main.async {

    animator.fractionComplete = 0.5
}

// Updates from 0.0 to 0.75 - Why now?
DispatchQueue.main.asyncAfter(deadline: .now() + 5) { 

    animator.fractionComplete = 0.75
}

      

Update: Putting these two lines before the first call seems like a workaround for the problem.

animator.startAnimation()
animator.pauseAnimation()

      

I am guessing this is an internal error. rdar: // 30856746

0
swift


source to share


No one has answered this question yet

See similar questions:

2
Animating the fractional part of the UIViewPropertyAnimator to blur the background

or similar:

458
UIScrollView Scrollable Content Size Ambiguity
3
Why use "unowned" in UIViewPropertyAnimator
2
How to properly handle this on iPhone X
2
UIViewPropertyAnimator does not work as expected when using initialVelocity
1
How do I automatically update a child view when the parent view changes?
1
Software restrictions don't work as expected
0
Error in UIViewPropertyAnimator when adding a lot of keyframes
0
UIViewPropertyAnimator for NSLayoutConstraints makes the view disappear
0
UIView borders don't change even after viewing DidLayoutSubviews
0
add subview to UITableViewcell to create custom table effects



All Articles
Loading...
X
Show
Funny
Dev
Pics