开发者

how to animate the uilabel view in such a way that it should keep moving from right side of the screen towards left , in obj c

开发者 https://www.devze.com 2023-03-16 06:03 出处:网络
how to animate 开发者_开发知识库the uilabel view insuch a way that it should keep moving from right side of the screen towards left,

how to animate 开发者_开发知识库the uilabel view in such a way that it should keep moving from right side of the screen towards left ,

i have used the folloiwing code but it didnt work

 UILabel * lbl =[UILabel alloc]init];

        CALayer *cloud = [CALayer layer];
        cloud.contents = lbl.text;
        cloud.bounds = CGRectMake(0, 40, 100, 30);

        cloud.position = CGPointMake(-45 ,30);
        //cloud.position = CGPointMake(self.view.bounds.size.width / 2,cloudImage.size.height / 2);

        [self.view.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 = 1;
        anim.duration = 5.0;
        [cloud addAnimation:anim forKey:@"position"];


It's a lot easier if you can use animateWithDuration in ios4

UILabel *label = //new label

[UIView animateWithDuration:1.0 animations:^{

   label.frame = //new frame

}];


You can do it like this:

    UILabel *label = [[UILabel alloc] initWithFrame:theRect];
[self.view addSubview:label];
[UIView animateWithDuration:0.5 
                      delay:0.0 
                    options:UIViewAnimationCurveEaseIn 
                 animations:^{label.bounds = targetRect;} 
                 completion:^(BOOL finished) { /* completion stuff */}];

There are more animate methods that take less parameters. You find them in the UIView documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消