使用下面的代码来实现选框效果。
声明CAShapeLayer对象
CAShapeLayer *_marque;
使用以下方法:
-(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;
}
现在调用方法
[self setMarquee];
[self showOverlayWithFrame:self.imgView.frame];
只需参考这个项目
https://www.cocoacontrols.com/controls/kaslideshow