- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用此代码绘制一条直线(显然是在用户触摸时),我需要显示从起点到用户按住触摸(未结束触摸)的直线,就像橡皮筋从起点,跟随手指移动。我可能忽略了一些我需要修改以产生必要效果的东西。任何想法?
注意:我在 View Controller 中。
- (void) drawLine:(UIPanGestureRecognizer *)sender
{
NSLog(@"Sender : %@", sender);
CGPoint currentPoint;
//CGAffineTransformMakeScale(lastScale, lastScale);
if([(UIPanGestureRecognizer *)sender state] == UIGestureRecognizerStateBegan || [(UIPanGestureRecognizer *)sender state] == UIGestureRecognizerStateChanged)
{
currentPoint = [(UIPanGestureRecognizer *)sender locationInView:imgView];
previousPoint = currentPoint;
}
if([(UIPanGestureRecognizer *)sender state] == UIGestureRecognizerStateChanged)
{
touchedPoint = [(UIPanGestureRecognizer *)sender locationInView:imgView];
[imgView setNeedsDisplay];
}
if([(UIPanGestureRecognizer *)sender state] == UIGestureRecognizerStateEnded)
{
currentPoint = [(UIPanGestureRecognizer *)sender locationInView:imgView];
imgView.image = [self drawLineFromPoint:previousPoint toPoint:currentPoint image:imgView.image];
previousPoint = currentPoint;
}
}
这是[drawline frompoint: topoint:]方法
UIGraphicsBeginImageContext(imgView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, imgView.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetShouldAntialias(context, YES);
CGContextSetLineWidth(context, 1.0f);
CGContextSetRGBStrokeColor(context, 0.7, 0.7, 0.7, 1.0);
CGContextMoveToPoint(context, fromPoint.x, fromPoint.y);
CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
CGContextDrawPath(context, kCGPathStroke);
CGContextRestoreGState(context);
NSLog(@"frompoint.x : %f, frompoint.y : %f",fromPoint.x, fromPoint.y );
NSLog(@"topoint.x : %f, topoint.y : %f", toPoint.x, toPoint.y);
UIImage *ret = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
最佳答案
DrawingApp这是我发现的一个示例项目,它可以完成所需的工作。
另一种方法是,正如 Lefteris 在评论中所建议的那样,在 UIView 中,覆盖触摸开始、移动和结束。并使用 drawRect 绘制线条。该线将拖动到您当前触摸的任何位置。
关于ios - 画一条直线 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12527482/
我想以 headless 模式(屏幕上根本没有 GUI)将 JPanel 绘制到 BufferedImage 中。 final JPanel panel = createPanel(); panel.
我是 Canvas 的新手,正在尝试创建看起来逼真的 float 粒子动画。 目前,我正在创建 400 个随机散布在 400x400 Canvas 上的粒子。 然后,在每个 requestAnimat
有没有办法在悬停时停止悬 float 画? :hover 这是一个显示动画的链接: https://codepen.io/youbiteme/pen/RprPrN 最佳答案 只需为您的 svg 悬停添
我想在谷歌地图上绘制覆盖图,其中除了特定点周围 1.5 公里半径以外的所有内容都被遮蔽了。为此,我尝试使用带有大量边框的圆圈,所以我会在边框中放置透明中心和覆盖颜色来实现这一点,但它无法渲染。
我正在尝试通过扩展类 UIView 来创建自定义 View ,该类可以在自定义 View 的中心显示一个圆圈。为了添加自定义绘图,我重写了 draw(_ rect: CGRect) 方法,如下所示。
我是一名优秀的程序员,十分优秀!