作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
那个灰色是 UIImageView,白色字体是 Image。
该图像放置在 UIImageView 内。
我喜欢只在字体内部着色,而不是整个 UIImageview,因为我要找出图像的坐标。
我是这种概念的新手,所以请有人指导我如何仅在图像内部着色,那里有 50 多张图像,它不是静态的,所以请给出一些好主意。
这是我用来在 UIImageView 中绘制的代码:
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
touchPoint = [touch locationInView:self.imgColor];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)];
[path addLineToPoint:CGPointMake(startingPoint.x,startingPoint.y)];
startingPoint=touchPoint;
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = [[UIColor blueColor] CGColor];
shapeLayer.lineWidth = 3.0;
shapeLayer.fillColor = [[UIColor redColor] CGColor];
[self.imgColor.layer addSublayer:shapeLayer];
[arrLayer addObject:shapeLayer];
NSLog(@"Touch moving point =x : %f Touch moving point =y : %f", touchPoint.x, touchPoint.y);
}
最佳答案
使用这个自定义 UIImage View :
自定义 View .h
@interface CustomView : UIImageView
@end
@interface CustomView ()
{
CGPoint touchPoint,startingPoint;
UIView *drawingView;
}
@end
@implementation CustomView
-(void)awakeFromNib
{
drawingView = [[UIView alloc] initWithFrame:self.bounds];
drawingView.backgroundColor = [UIColor clearColor];
[self addSubview:drawingView];
[self updateMask];
}
- (void)updateMask
{
CALayer *maskLayer = [CALayer layer];
maskLayer.geometryFlipped = YES;
maskLayer.contents = (id)self.image.CGImage;
switch (self.contentMode)
{
case UIViewContentModeScaleToFill:
maskLayer.contentsGravity = kCAGravityResize;
break;
case UIViewContentModeScaleAspectFit:
maskLayer.contentsGravity = kCAGravityResizeAspect;
break;
case UIViewContentModeScaleAspectFill:
maskLayer.contentsGravity = kCAGravityResizeAspectFill;
break;
case UIViewContentModeCenter:
maskLayer.contentsGravity = kCAGravityCenter;
break;
case UIViewContentModeTop:
maskLayer.contentsGravity = kCAGravityTop;
break;
case UIViewContentModeBottom:
maskLayer.contentsGravity = kCAGravityBottom;
break;
case UIViewContentModeLeft:
maskLayer.contentsGravity = kCAGravityLeft;
break;
case UIViewContentModeRight:
maskLayer.contentsGravity = kCAGravityRight;
break;
case UIViewContentModeTopLeft:
maskLayer.contentsGravity = kCAGravityTopLeft;
break;
case UIViewContentModeTopRight:
maskLayer.contentsGravity = kCAGravityTopRight;
break;
case UIViewContentModeBottomLeft:
maskLayer.contentsGravity = kCAGravityBottomLeft;
break;
case UIViewContentModeBottomRight:
maskLayer.contentsGravity = kCAGravityBottomRight;
break;
default:
break;
}
maskLayer.frame = drawingView.bounds;
drawingView.layer.mask = maskLayer;
}
- (void)setImage:(UIImage *)image
{
[super setImage:image];
[self updateMask];
}
- (void)layoutSubviews
{
[super layoutSubviews];
drawingView.frame = self.bounds;
drawingView.layer.mask.frame = drawingView.bounds;
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
touchPoint = [touch locationInView:self];
if (!CGPointEqualToPoint(startingPoint, CGPointZero))
{
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)];
[path addLineToPoint:CGPointMake(startingPoint.x,startingPoint.y)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = [[UIColor blueColor] CGColor];
shapeLayer.lineWidth = 3.0;
shapeLayer.fillColor = [[UIColor redColor] CGColor];
[drawingView.layer addSublayer:shapeLayer];
}
startingPoint=touchPoint;
// [arrLayer addObject:shapeLayer];
NSLog(@"Touch moving point =x : %f Touch moving point =y : %f", touchPoint.x, touchPoint.y);
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
{
startingPoint = CGPointZero;
}
@end
关于ios - 如何找出无色区域uibezierpath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34736949/
我正在处理旧视频,我基本上将它们转换为 HVEC 并锐化,所以我的命令看起来像这样 .\ffmpeg.exe -i F:\file.mkv -vf unsharp=3:3:1.5 -c:v hevc_
我是一名优秀的程序员,十分优秀!