現在、5秒ごとに別の画像と交換される画像が画面にあり、アニメーションを使用してそうしています。
同時に画面上に、ユーザーが拾ってドラッグできるオブジェクトがあります(パンジェスチャーを使用)。アニメーションの 0.5 時間の間にオブジェクトの周りを移動すると、UI が途切れます。たとえば、ブラシを手に取って画面上を移動します。5 秒のタイマーが終了し、背景画像が更新されます。これにより、アニメーションの発生中にブラシのスタッターが更新されます。UI スレッドをロードするイメージを移動し、NSData を使用して強制的にロードします。
画像を変更するアニメーションの実行中に、このスタッターを防ぐ方法はありますか? 画像の差し替えはこんな感じ。
// Dispatch to the queue, and do not wait for it to complete
// Grab image in background thread in order to not block UI as much as possible
dispatch_async(imageGrabbingQueue, ^{
curPos++;
if (curPos> (self.values.count - 1)) curPos= 0;
NSDictionary *curValue = self.values[curPos];
NSString *imageName = curValue [KEY_IMAGE_NAME];
// This may cause lazy loading later and stutter UI, convert to DataObject and force it into memory for faster processing
UIImage *imageHolder = [UIImage imageNamed:imageName];
// Load the image into NSData and recreate the image with the data.
NSData *imageData = UIImagePNGRepresentation(imageHolder);
UIImage *newImage = [[UIImage alloc] initWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
[UIView transitionWithView:self.view duration:.5 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionAllowAnimatedContent
animations:^{
[self.image setImage:newImage ];
// Temp clause to show ad logo
if (curPos != 0) [self.imagePromotion setAlpha:1.0];
else [self.imagePromotion setAlpha:0];
}
completion:nil];
});
});
ありがとう、Dマン