Marquee Animation UIimageView blur

这一生的挚爱 提交于 2019-12-13 21:12:16

问题


In my app images are in Marquee effect (HTML) . so i set the x point of image by using NSTimer but it implemented successfully but the image show some blur. how i remove this blur effect ?
int x=0;
ImgArray=[[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:@"keyframe1.png"],[UIImage imageNamed:@"keyframe2.png"],[UIImage imageNamed:@"keyframe3.png"],[UIImage imageNamed:@"keyframe4.png"], [UIImage imageNamed:@"keyframe5.png"],nil];

imgView=[[UIImageView alloc]initWithFrame:CGRectMake(x, 0, 1024, 768)];`
imgView.image=[ImgArray objectAtIndex:0];
[self.view addSubview:imgView];
[NSTimer scheduledTimerWithTimeInterval:.08 target:self selector:@selector(showMarquee) userInfo:nil repeats:YES];

in showMarquee method change the value of x


回答1:


Use the below code for marquee effect.

declare CAShapeLayer object

CAShapeLayer *_marque;

Use the below methods:

-(void)setMarquee   {

    if (!_marque) {
        _marque = [CAShapeLayer layer] ;
        _marque.fillColor = [[UIColor clearColor] CGColor];
        _marque.strokeColor = [[UIColor grayColor] CGColor];
        _marque.lineWidth = 1.0f;
        _marque.lineJoin = kCALineJoinRound;
        _marque.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:5], nil];
        _marque.bounds = CGRectMake(self.imgView.frame.origin.x, self.imgView.frame.origin.y, 0, 0);
        _marque.position = CGPointMake(self.imgView.frame.origin.x + self.imgView.frame.origin.x, self.imgView.frame.origin.y + self.imgView.frame.origin.y);
    }
    [self.view.layer addSublayer:_marque];
}

-(void)showOverlayWithFrame:(CGRect)frame {

        if (![_marque actionForKey:@"linePhase"]) {
            CABasicAnimation *dashAnimation;
            dashAnimation = [CABasicAnimation animationWithKeyPath:@"lineDashPhase"];
            [dashAnimation setFromValue:[NSNumber numberWithFloat:0.0f]];
            [dashAnimation setToValue:[NSNumber numberWithFloat:15.0f]];
            [dashAnimation setDuration:0.5f];
            [dashAnimation setRepeatCount:HUGE_VALF];
            [_marque addAnimation:dashAnimation forKey:@"linePhase"];
        }

        _marque.bounds = CGRectMake(frame.origin.x, frame.origin.y, 0, 0);
        _marque.position = CGPointMake(frame.origin.x + self.imgView.frame.origin.x, frame.origin.y + self.imgView.frame.origin.y);

        CGMutablePathRef path = CGPathCreateMutable();
        CGPathAddRect(path, NULL, frame);
        [_marque setPath:path];
        CGPathRelease(path);

        _marque.hidden = NO;


}

Now call the methods

[self setMarquee];
[self showOverlayWithFrame:self.imgView.frame];

Just refer this project

https://www.cocoacontrols.com/controls/kaslideshow



来源:https://stackoverflow.com/questions/19996819/marquee-animation-uiimageview-blur

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!