5

Próbuję zwiększyć wysokość niestandardowej klawiatury w animacji za pomocą następującego kodu. Ale nie mogę zrozumieć, dlaczego zmiana następuje natychmiast, ignorując animację.Animowanie niestandardowej wysokości klawiatury w systemie iOS 8

//In viewDidAppear 

[self.view needsUpdateConstraints]; 
[UIView animateWithDuration:2 animations:^{ 
    CGFloat _expandedHeight = 500; 
    NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint 
      constraintWithItem: self.view 
      attribute: NSLayoutAttributeHeight 
      relatedBy: NSLayoutRelationEqual 
      toItem: nil 
      attribute: NSLayoutAttributeNotAnAttribute 
      multiplier: 0.0 
      constant: _expandedHeight]; 
    [self.view addConstraint: _heightConstraint]; 
    [self.view layoutIfNeeded]; 
}]; 

Odpowiedz

0

najpierw dodać contraints zewnątrz bloku animacji, a następnie zadzwonić do updateConstraints, a wewnątrz bloku animacji, zadzwoń layoutIfNeeded .Hope to zadziała

CGFloat _expandedHeight = 500; 
NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint 
     constraintWithItem: self.view 
     attribute: NSLayoutAttributeHeight 
     relatedBy: NSLayoutRelationEqual 
     toItem: nil 
     attribute: NSLayoutAttributeNotAnAttribute 
     multiplier: 0.0 
     constant: _expandedHeight]; 
[self.view addConstraint: _heightConstraint]; 
[self.view needsUpdateConstraints]; 
[UIView animateWithDuration:2 animations:^{ 

[self.view layoutIfNeeded]; 
}]; 
+0

Kiedy próbuję tego rozwiązania, czas trwania nadal nie jest brany pod uwagę. – Drico

+0

ktoś znalazł jakieś rozwiązanie? – Renatus

+0

Najlepszym znalezionym rozwiązaniem jest użycie programu CADisplayLink. To rozwiązanie działa, ale nie jest wystarczająco stabilne. –

0

Poniższy kod jest użyć do animowania środkowa pozycja X linii. Połączyłem środek X tej linii z jakimś centrum widoku referencyjnego za pomocą IBOutlet NSLayoutConstraint. Inorder dla animacji pojawiających się przy autolayout wymaga aktualizacji ograniczenia i wywołania layoutIfNeeded wewnątrz bloku animacji. Jest to zdecydowanie idea animacji z autolayout.

blueScrollerCenterXConstraint.constant = (btn.tag - 4000)*btn.frame.size.width; 
    [blueScroller updateConstraints]; 

    [UIView animateWithDuration:0.3 animations:^{ 
    [blueScroller layoutIfNeeded]; 
}]; 
0
  1. nie powinien dodać ograniczenie tam.

  2. Dodaj i wyłącz (lub ustaw naprawdę bardzo niski priorytet).

  3. Po tym należy zmienić priorytet na 999 i wywołać layoutIfNeded w bloku animacji.

Powiązane problemy