【问题标题】:Draw swipe with UIBezierPath in UIImageView在 UIImageView 中使用 UIBezierPath 绘制滑动
【发布时间】:2013-08-26 04:25:13
【问题描述】:

我正在尝试在 UIImageView 中绘制一些东西。我可以使用以下代码在 UIView 中毫无问题地绘制:

@implementation DrawView
{
    UIBezierPath *path; 
}

- (id)initWithCoder:(NSCoder *)aDecoder 
{
    if (self = [super initWithCoder:aDecoder])
    {
        [self setMultipleTouchEnabled:NO]; 
        [self setBackgroundColor:[UIColor whiteColor]];
        path = [UIBezierPath bezierPath];
        [path setLineWidth:2.0]; 
    }
    return self;
}

- (void)drawRect:(CGRect)rect 
{
    [[UIColor blackColor] setStroke];
    [path stroke];
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
    [path moveToPoint:p];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
    [path addLineToPoint:p]; // (4)
    [self setNeedsDisplay];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self touchesMoved:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self touchesEnded:touches withEvent:event];
}

这会跳过 imageview.. 我需要的是相反的。我想画一个 uiimageview 并跳过 uiview .. 我该怎么做?提前谢谢..

【问题讨论】:

    标签: uiview uiimageview drawing drawrect uibezierpath


    【解决方案1】:

    绘图表面必须是此视图集层次结构中的父级。这样您就可以在父视图上绘制,而图像位于下方。

    -Main View
    --Drawing View
    ---UIImageView
    

    【讨论】:

    • 如果您需要绘图视图的大小与图像视图相同,只需将其边界/框架调整为其子图像视图的大小。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    • 1970-01-01
    • 2015-12-09
    • 2016-10-09
    • 2021-02-13
    • 2017-09-12
    相关资源
    最近更新 更多