3

I'm wondering why views in my custom TableViewCells are affected by animation which should animate only 2 views in my floating pager (which is even not in TableView's view hierarchy..

UIView.animate(withDuration: 0.3) {
    self.stateIndicator.isHiddenInStackView = true
    self.loaderIndicator.isHiddenInStackView = false
}

When I comment out animation block everything stops animating.

Attached GIF describes everything (Blue views gets animated corner radius, badges 'flies in' instead of just appearing):

UIView.animate strange behavior

enter image description here

Any help or hint will be appreciated :).

Regards Tom.

a.masri
  • 2,439
  • 1
  • 14
  • 32
  • What is `isHiddenInStackView`? Is this property's setter doing something? – mag_zbc Jun 07 '18 at 11:13
  • It's only "safe-hide-unhide" var isHiddenInStackView: Bool { get { return isHidden } set { if isHidden != newValue { isHidden = newValue } } } "The bug is that hiding and showing views in a stack view is cumulative. Weird Apple bug." Source: https://stackoverflow.com/a/45599835/9413528 – Tomasz Kamiński Jun 07 '18 at 11:17
  • I don’t think that bug is relevant. It just says that you’re have to set `isHidden` multiple times to have an affect. – ABeard89 Jun 07 '18 at 11:21
  • My guess would be that since your pager is getting data about the table view, it might be triggering a table view reload somehow. If that table reload is triggered indirectly by the pager, then it’s changes might get caught by the animation block. – ABeard89 Jun 07 '18 at 11:24
  • @ABeard89 I'm updating the pager after table view gets more data from background thread. So pager do nothing with table view at all. – Tomasz Kamiński Jun 07 '18 at 11:26
  • can you share the code below these lines `UIView.animate(withDuration: 0.3) { self.stateIndicator.isHiddenInStackView = true self.loaderIndicator.isHiddenInStackView = false }` – sanjaykmwt Jun 07 '18 at 11:35
  • @ABeard89 you were 100% right! I had to move pager initialization code to viewDidAppear (from viewWillAppear) and it worked without wrapping things into UIView.performWithoutAnimation {}. Animation block was the issue here, somehow. Thanks! – Tomasz Kamiński Jun 07 '18 at 11:52
  • Great! I’m glad the timing fixed the issue! (`performWithoutAnimation` seems like a hack to me.) – ABeard89 Jun 07 '18 at 11:56

2 Answers2

2

Write the things which you don't want to animate in the block

  UIView.performWithoutAnimation {
     //Write your code here
  }
sanjaykmwt
  • 586
  • 3
  • 19
0

I make my animation in main queue and it worked. For example

DispatchQueue.main.async {
     //Write animation code here
}
Birju
  • 1,132
  • 11
  • 32