目前我在屏幕上有一个图像,每 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];
});
});
谢谢, 曼