跑马灯

来源:互联网 发布:广州知用中学地址 编辑:程序博客网 时间:2024/04/30 04:39

CGSize          _titleSize;  


if (strName&&([strName length] >0)){

        _titleLabel.text = strName;

        _titleSize = [strName sizeWithAdapterFont:[UIFont boldSystemFontOfSize:17.0f]

                                constrainedToSize:CGSizeMake(MAXFLOAT,25.0f)];

        _pmdScrollView.contentSize =CGSizeMake(_titleSize.width +250.0f*2,25.0f);

        _titleLabel.frame =CGRectMake(250.0f,0.0f, _titleSize.width,25.0f);

        [selfstartAnimation];

    }





_pmdScrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(35.0f, fh+9.5f,250.0f,25.0f)];

        _pmdScrollView.backgroundColor = [UIColorclearColor];

        _pmdScrollView.showsHorizontalScrollIndicator =NO;

        _pmdScrollView.showsVerticalScrollIndicator =NO;

        _pmdScrollView.userInteractionEnabled =NO;

        _pmdScrollView.scrollEnabled =NO;

        _pmdScrollView.canCancelContentTouches =NO;

        _pmdScrollView.delaysContentTouches =NO;

        _titleLabel = [[UILabelalloc]initWithFrame:CGRectMake(0.0f,0.0f,250.0f,25.0f)];

        _titleLabel.backgroundColor = [UIColorclearColor];

        _titleLabel.textAlignment =GNTextAlignmentCenter;

        _titleLabel.textColor = [UIColorwhiteColor];

        _titleLabel.font = [UIFontboldSystemFontOfSize:17.0f];

        [_pmdScrollView addSubview:_titleLabel];

        [selfaddSubview:_pmdScrollView];




- (void)startAnimation

{

    _pmdScrollView.contentOffset =CGPointMake(0.0f,0.0f);

    [UIViewbeginAnimations:@"MarqueeBarAniamation"context:nil];

    [UIViewsetAnimationCurve:UIViewAnimationCurveLinear];

    CGFloat time = _titleSize.width/250.0f;

    if((NSInteger)time<1){

        time = 1;

    }

    [UIViewsetAnimationDuration:8*time];

    [UIViewsetAnimationDelegate:self];

    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

    _pmdScrollView.contentOffset =CGPointMake(_pmdScrollView.contentSize.width -250.0f, 0.0f);

    [UIViewcommitAnimations];

}




- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context

{

    if ([animationID isEqualToString:@"MarqueeBarAniamation"]){

        if ([finished boolValue] >0){

            [self startAnimation];

        }

    }

}


原创粉丝点击