【问题标题】:UIView Re-Appear on Screen as it Leaves the Other Side?UIView 在离开另一边时重新出现在屏幕上?
【发布时间】:2014-03-18 09:25:41
【问题描述】:

我有一个名为 clouds 的 UIView。它当前移动到屏幕的右侧,一旦全部离开,它就会重新出现在左侧。

如何让它在离开右侧时重新出现在左侧?所以当它开始从右侧离开时,刚刚消失的位又出现在左侧。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    movement = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(moving) userInfo:nil repeats:YES];

    cloudsMovement = 2;

}

-(void)platformMovement{
    clouds.center = CGPointMake(clouds.center.x + cloudsMovement, clouds.center.y);

}

-(void)moving{

    if (clouds.center.x < -11){
        clouds.center = CGPointMake(330, clouds.center.y);
    }
    if (clouds.center.x > 330){
        clouds.center = CGPointMake(-11, clouds.center.y);
    }

    [self platformMovement];

}

任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: iphone animation uiview uiimageview


    【解决方案1】:

    回答我自己的问题似乎有点不寻常,但为了帮助像我这样的任何其他初学者,这是我想出的解决方案:

    创建另一个 UIView(我称之为 cloud2)。 将其移出屏幕左侧,并将其设置为原始 UIView (clouds1) 的动画。 稍微调整一下数字,以便当整个图像离开屏幕时,它会重新出现在左侧。有点像传送带系统。

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        movement = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(moving) userInfo:nil repeats:YES];
    
        cloudsMovement = 2;
    }
    
    -(void)platformMovement{
        clouds1.center = CGPointMake(clouds1.center.x + cloudsMovement, clouds1.center.y);
    
        clouds2.center = CGPointMake(clouds2.center.x + cloudsMovement, clouds1.center.y);
    
    }
    
    -(void)moving{
    
        if (clouds1.center.x > 470){
            clouds1.center = CGPointMake(-150, clouds1.center.y);
        }
    
        if (clouds2.center.x > 470){
            clouds2.center = CGPointMake(-150, clouds2.center.y);
        }
    
        [self platformMovement];
    
    }
    

    【讨论】:

    • 这是我的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多