2017-08-31 2 views
0

アニメーションのブロックでlayoutIfNeededを呼び出すと、同じ問題が発生しましたか?アニメーションブロックでレイアウトを呼び出すと、iPhone 7のUIがフリーズする

私は方法があります:

- (void)hide { 
dispatch_block_t onMain = ^{ 
    CGFloat height = -viewContent.frame.size.height; 

    [UIView animateKeyframesWithDuration:0.15f delay:0 options:0 animations:^{ 
     [UIView addKeyframeWithRelativeStartTime:0.f relativeDuration:0.7f animations:^{ 
      self.constraintViewContentBottom.constant = height/3; 
      [self layoutIfNeeded]; 
     }]; 
     [UIView addKeyframeWithRelativeStartTime:0.7f relativeDuration:0.3f animations:^{ 
      self.constraintViewContentBottom.constant = height; 
      [self layoutIfNeeded]; 
     }]; 
    } completion:^(BOOL finished) { 
     [UIView animateWithDuration:0.2f animations:^{ 
      self.viewBackground.alpha = 0.0f; 
     } 
         completion:^(BOOL finished) { 
          self.hidden = YES; 
         }]; 
    }]; 
}; 
if([NSThread isMainThread]) { 
    onMain(); 
} 
else { 
    dispatch_sync(dispatch_get_main_queue(), onMain); 
} 
} 

多くのデバイス上で完璧に動作しますが、1 iPhone 7、ライン上:UIをフリーズ[self layoutIfNeeded];を。

私はそのデバイスをデバッグできませんが、いくつかのログを取得できます。

誰でも問題を解決できる方法を知っていますか?

ありがとうございました。

答えて

0

アニメーションブロックの前に、の制約の定数を設定します。 layoutIfNeededはブロックに入れなければならない唯一のものです...

+0

基本的に[UIView animateWithDuration:0.2f animations:^ {}]から呼び出すと、方法 - あなたは正しい。しかし、私はさまざまな変種を試みました - 前に、内部 - 結果は同じです。 = – Andrei

+1

そして、あなたは 'dispatch_sync'を使う必要がありますか? –

+0

dispatch_syncを使用しないでください! –

関連する問題