I am using aNSTimer to update aUIButton's title every second.
It works but the text in the title blinks (animates to alpha0 and back) automatically.
I tried to usebutton.layer.removeAllAnimations() with no luck, and no exceptions, so QuartzCore seems to be correctly linked.
Current non-working paranoid code:
UIView.setAnimationsEnabled(false)UIView.performWithoutAnimation { button.setTitle(time, forState: .Normal) button.layer.removeAllAnimations() }UIView.setAnimationsEnabled(true)- Did you try to wrap it with
UIView'sperformWithoutAnimation(_ actionsWithoutAnimation: () -> Void)(iOS >= 7)? OrsetAnimationsEnabled(_ enabled: Bool)?zrzka– zrzka2015-04-14 14:57:10 +00:00CommentedApr 14, 2015 at 14:57
3 Answers3
Make sure your button is a "custom" button and not a "system" button.
If you created it on a storyboard, then just change the Button Type. If you created it programmatically, then it should be:
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];2 Comments
I’ve made a Swift extension to do this:
extension UIButton { func setTitleWithOutAnimation(title: String?) { UIView.setAnimationsEnabled(false) setTitle(title, forState: .Normal) layoutIfNeeded() UIView.setAnimationsEnabled(true) }}Works for me on iOS 8 and 9, withUIButtonTypeSystem.
3 Comments
You can perform Button changes inside the closure:
UIView.performWithoutAnimation { //Button changes button.layoutIfNeeded()}Hope this helps.
4 Comments
Explore related questions
See similar questions with these tags.