Can we stop or remove the animation effect in focus using UIButton and give a different tvOS border effect

In the bottom delegate function I tried to do, but did'nt get the desired result

override func didUpdateFocusInContext(context: UIFocusUpdateContext,withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
    if (context.nextFocusedView == self) {
        coordinator.addCoordinatedAnimations({ () -> Void in
            self.animationDidStop(CAAnimation(), finished: true)
            }, completion: { () -> Void in

        })

    }
    else {
        // handle unfocused appearance changes

        coordinator.addCoordinatedAnimations({ () -> Void in
            self.animationDidStop(CAAnimation(), finished: true)
            }, completion: { () -> Void in

        })
    }
    context.nextFocusedView?.layer.shadowOffset = CGSizeZero
    context.nextFocusedView?.layer.shadowOpacity = 0.9;
    context.nextFocusedView?.layer.shadowRadius = 0;
    context.nextFocusedView?.layer.shadowColor= UIColor.orangeColor().CGColor
    context.previouslyFocusedView?.layer.shadowOpacity = 0;
}
+4
source share
1 answer

First of all, you must set the button type to Custom Type . By individual type, you will not get more system animations, so you have to do all the animations yourself.

didUpdateFocusInContext UIViewController, UIButton, .

, UIButton. .

let scale = 1.1    
layer.borderColor = UIColor.redColor().CGColor

override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {

    if context.nextFocusedView == self {
        coordinator.addCoordinatedAnimations({ () -> Void in

            self.transform = CGAffineTransformMakeScale(scale, scale)
            self.layer.borderWidth = 2

            }, completion: nil)
    }
    else {
        coordinator.addCoordinatedAnimations({ () -> Void in

            self.transform = CGAffineTransformIdentity
            self.layer.borderWidth = 0

            }, completion: nil)
    }
}
+3

Source: https://habr.com/ru/post/1613365/


All Articles