实现上下轮番滚动播放的动画

#import "ViewController.h"

@interface ViewController ()
{
    UILabel * lable1;
    UILabel * lable2;
    CGRect frame1;
    CGRect frame2;
    CGRect frame3;
    NSMutableArray * lableArray;
}
@property (weak, nonatomic) IBOutlet UIView *bgview;

- (IBAction)action:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    lableArray =[NSMutableArray array];
    lable1 =[[UILabel alloc]init];
    lable2 =[[UILabel alloc]init];
    frame1 =CGRectMake(0, -50, 320, 50);
    frame2 =CGRectMake(0, 0, 320, 50);
    frame3 =CGRectMake(0, 50, 320, 50);
    lable1.frame =frame1;
    lable2.frame =frame2;
    lable1.text =@"第1个";
    lable2.text =@"第2个";
    
    [_bgview addSubview:lable1];
    [_bgview addSubview:lable2];
    _bgview.clipsToBounds =YES;
    [lableArray addObject:lable1];
    [lableArray addObject:lable2];
    NSTimer * timer =[NSTimer scheduledTimerWithTimeInterval:3.5 target:self selector:@selector(Actions:) userInfo:nil repeats:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)Actions:(id)sender
{
    
    [UIView animateWithDuration:3.0 animations:^{
        UILabel * lab1 =(UILabel*)lableArray[0];
        UILabel * lab2 =(UILabel*)lableArray[1];
        lab1.frame =frame2;
        lab2.frame =frame3;
    } completion:^(BOOL finished) {
        UILabel * lab2 =(UILabel*)lableArray[1];
        lab2.frame =frame1;
        [lableArray exchangeObjectAtIndex:0 withObjectAtIndex:1];
    }];
}


转载于:https://my.oschina.net/u/2519763/blog/643694

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值