小编r00*_*b0x的帖子

在无缝循环中动画无限滚动图像

目前我有一张2048x435云的图像,使用CABasicAnimation滚动横跨面向大陆的UIDmageView 1024x435.云图像应该滚动,但是我在尝试获取重复的云图像以连接到当前云图像的背面时遇到了一些麻烦,因此云图像之间没有间隙.我一直在努力寻找一个解决方案,所以任何帮助都会非常感激.我目前的代码:

开发Xcode 4.2 for iOS 5,采用ARC非故事板ipad景观定位.

-(void)cloudScroll
{
    UIImage *cloudsImage = [UIImage imageNamed:@"TitleClouds.png"];
    CALayer *cloud = [CALayer layer];
    cloud.contents = (id)cloudsImage.CGImage;
    cloud.bounds = CGRectMake(0, 0, cloudsImage.size.width, cloudsImage.size.height);
    cloud.position = CGPointMake(self.view.bounds.size.width / 2, cloudsImage.size.height / 2);
    [cloudsImageView.layer addSublayer:cloud];

    CGPoint startPt = CGPointMake(self.view.bounds.size.width + cloud.bounds.size.width / 2, cloud.position.y);
    CGPoint endPt = CGPointMake(cloud.bounds.size.width / -2, cloud.position.y);
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position"];
    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    anim.fromValue = [NSValue valueWithCGPoint:startPt];
    anim.toValue = [NSValue valueWithCGPoint:endPt];
    anim.repeatCount = HUGE_VALF;
    anim.duration = 60.0;
    [cloud addAnimation:anim forKey:@"position"]; …
Run Code Online (Sandbox Code Playgroud)

xcode cocoa-touch objective-c ipad

23
推荐指数
2
解决办法
1万
查看次数

标签 统计

cocoa-touch ×1

ipad ×1

objective-c ×1

xcode ×1