0

In a similar post, I found a solution to animating a scrolling image infinitely:

Animate infinite scrolling of an image in a seamless loop

While this solution works beautifully, there seems to be an issue when running on a retina device. In particular, I am running this project on an iPad only. A non-retina iPad 2 scrolls the image without any problems. But run on a retina iPad 3 or 4 the image is a mess! It's difficult to describe, but the best I can say is that it is garbled. Pixels are stretched every which way. It resembles a Jackson Pollak painting.

Screen shot:

http://imgur.com/Q7n08kv

I tested this using a non-retina image (non 2x) and a retina version (@2x). The image is large - full screen (landscape) and is 4 panels wide (4096 x 768). I played around with smaller images but with the same result.

Is there a limitation with the scrolling functionality of CABasicAnimation that would affect retina devices? Here is the code I am using (as contributed by rob mayoff):

UIImage *crawlImage = [UIImage imageNamed:@"CrawlBackground.png"];
UIColor *crawlPattern = [UIColor colorWithPatternImage:crawlImage];
self.crawlLayer = [CALayer layer];
self.crawlLayer.backgroundColor = crawlPattern.CGColor;

self.crawlLayer.transform = CATransform3DMakeScale(1, -1, 1);
self.crawlLayer.anchorPoint = CGPointMake(0, 1);

self.crawlLayer.frame = CGRectMake(0, 0, crawlImage.size.width + 1024, crawlImage.size.height);

[self.backgroundCrawl.layer addSublayer:self.crawlLayer];
self.backgroundCrawl.layer.zPosition = 0;

CGPoint startPoint = CGPointZero;
CGPoint endPoint = CGPointMake(-crawlImage.size.width, 0);

self.crawlLayerAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
self.crawlLayerAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
self.crawlLayerAnimation.fromValue = [NSValue valueWithCGPoint:startPoint];
self.crawlLayerAnimation.toValue = [NSValue valueWithCGPoint:endPoint];
self.crawlLayerAnimation.repeatCount = HUGE_VALF;
self.crawlLayerAnimation.duration = 30;   // nn seconds to complete the cycle
2
  • Perhaps you could upload a screen shot to imgur.com and post a link to it.
    – rob mayoff
    Mar 1, 2013 at 5:36
  • I've edited the question and added a link to a screen capture of what the problem looks like. Mar 2, 2013 at 1:07

2 Answers 2

0
self.crawlLayer = [CALayer layer];

As soon as you make a layer you should set its contentsScale:

self.crawlLayer.contentsScale = [[UIScreen mainScreen] scale];

Otherwise it may not display correctly on double-resolution screens.

0

self.crawlLayer.contents = (id)crawlImage.CGImage;

or:

self.crawlLayer.contents = (__bridge id)([crawlImage CGImage]);

This should fix it. Allowing large images to scroll correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.