lab上下滚动,类似淘宝上的头条

前段时间,因项目需要,做了一个label上下滚动的效果,类似淘宝上的头条,小功能,觉得有点实用仅供参考,思路很简单就是用scrollerview,设置一个定时器3秒滚动一次,放了项目代码片段,所有代码都在上,源码就不贴上去了

- (void)mainNewsRefresh {
    // noticeScroller ,xib里scrollerView
    NSArray *subViews = [self.noticeScroller subviews];
    for (UIView *view in subViews) {
        [view removeFromSuperview];
    }

    float x = 0.0;
    float y = 0;
    float w = 275;
    float h = 35;
    
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    but.frame = CGRectMake(x, y, w, h);
    but.tag = countInt;
    [but addTarget:self action:@selector(noticeButAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.noticeScroller addSubview:but];
    
    y += h;
    
    self.noticeScroller.contentSize = CGSizeMake(x, y);
     // 计时器,3秒滚动一次
    [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(displayNews) userInfo:nil repeats:YES];
}

-(void)displayNews{
    
    countInt++; // int类型,初始化为countInt=0 
    if (countInt >= [mubArray count])
        countInt=0;
    CATransition *animation = [CATransition animation];
    animation.delegate = self;
    animation.duration = 0.5f ;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = YES;
    animation.type = @"cube";
    
    // 需要滚动显示的文字在mubArray数组里面,数组里面嵌套的是一个字典
    Lab.text = [[mubArray objectAtIndex:countInt] objectForKey:@"title"];
    // 视图_footAdvertUIViwView
    [_footAdvertUIViw.layer addAnimation:animation forKey:@"animationID"];
}
// button点击事件
- (void)noticeButAction:(id)sender{
    
    if (countInt >= [mubArray count])
        countInt=0;
    
    noticeDict = [mubArray objectAtIndex:countInt];
    
    if (noticeDict != nil) { 
        WebView *WebView = [[WebView alloc] initWithNibName:@"WebView" bundle:nil];
        [WebView initData:noticeDict];
        [self presentViewController:WebView animated:YES completion:nil];
    }
}


奉上一张项目效果图,时间效果和淘宝一样,只是它一次滚动两条,我只需要一条

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值