ios – 在屏幕上水平滑动时循环的图像,看起来像无限滚动

ios – 在屏幕上水平滑动时循环的图像,看起来像无限滚动,第1张

概述我想有一个视图控制器在背景中循环图像,使外观无限滚动.例如,如果我使用下面的图像,左右边缘完美匹配,并将用于提供无限滚动外观.有谁知道我怎么设置这个?我做了一些研究而且迷路了.谢谢你们! 我这样做.编辑而不是将其作为读者的练习,更新以显示如何向任一方向平移…… @property (nonatomic, assign) BOOL keepGoing;@property (nonatomic, a 我想有一个视图控制器在背景中循环图像,使外观无限滚动.例如,如果我使用下面的图像,左右边缘完美匹配,并将用于提供无限滚动外观.有谁知道我怎么设置这个?我做了一些研究而且迷路了.谢谢你们!解决方法 我这样做.编辑而不是将其作为读者的练习,更新以显示如何向任一方向平移……

@property (nonatomic,assign) BOol keepGoing;@property (nonatomic,assign) BOol panRight;@property (nonatomic,strong) UIImageVIEw *imageVIEwA;@property (nonatomic,strong) UIImageVIEw *imageVIEwB;- (voID)getReady {    // init theImage    UIImage *theImage = [UIImage imagenamed:@"theImage.png"];    // get two copIEs of the image    self.imageVIEwA = [[UIImageVIEw alloc] initWithImage:theImage];    self.imageVIEwB = [[UIImageVIEw alloc] initWithImage:theImage];    // place one in vIEw,the other,off to the right (for right to left motion)    NSInteger direction = (self.panRight)? 1 : -1;    self.imageVIEwA.frame = self.vIEw.bounds;    self.imageVIEwB.frame = CGRectOffset(self.vIEw.bounds,direction*self.imageVIEwA.bounds.size.wIDth,0.0);    [self.vIEw addSubvIEw:self.imageVIEwA];    [self.vIEw addSubvIEw:self.imageVIEwB];    self.keepGoing = YES;}- (voID)go {    NSInteger direction = (self.panRight)? 1 : -1;    CGfloat offsetX = -direction*self.imageVIEwA.bounds.size.wIDth;    [UIVIEw animateWithDuration:1.0 delay:0.0 options:UIVIEwAnimationoptionCurvelinear animations:^{        self.imageVIEwA.frame = CGRectOffset(self.imageVIEwA.frame,offsetX,0);        self.imageVIEwB.frame = CGRectOffset(self.imageVIEwB.frame,0);    } completion:^(BOol finished) {        if (self.keepGoing) {            // Now B is where A began,so swap them and reposition B            UIImageVIEw *temp = self.imageVIEwA;            self.imageVIEwA  = self.imageVIEwB;            self.imageVIEwB = temp;            self.imageVIEwB.frame = CGRectOffset(self.vIEw.bounds,direction*self.vIEw.bounds.size.wIDth,0.0);            // recursive call,but we don't want to wind up the stack            [self performSelector:@selector(go) withObject:nil afterDelay:0.0];        }    }];}

要进行 *** 作,请设置panRight属性,然后调用[self getReady];和[自我去];

它将主要运行asynch.要使其停止,请设置self.keepGoing = NO;.

总结

以上是内存溢出为你收集整理的ios – 在屏幕上水平滑动时循环的图像,看起来像无限滚动全部内容,希望文章能够帮你解决ios – 在屏幕上水平滑动时循环的图像,看起来像无限滚动所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1075703.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存