iOS Animate Dashed Rectangle Border

У меня есть UIImageView, отображающий изображение. Я хочу «выделить» часть изображения, нарисовав округленный контур прямоугольника. Мне бы хотелось, чтобы контур был нарисован толстой пунктирной линией, которая «анимирует», постоянно изменяя, с чего начинается «начало» линии.

Я думал о том, чтобы нарисовать круг, который имел нужный мне вид, и затем просто анимировать его, но мне действительно нужно прямоугольное решение, так что это не так.

Фон:

Я рисую закругленную прямоугольную границу, вычисляя 8 точек и рисуя 4 прямые линии и 4 кривые. (Возможно, это может быть проще, но это не ломаная часть!)

Я думаю, что я буду использовать переменную «смещение», которая начинается в верхней левой части скругленного прямоугольника, где верхняя левая кривая встречается с верхней прямой частью. Затем я увеличу это «смещение» по верху скругленного прямоугольника до тех пор, пока он не достигнет кривой сверху вправо, после чего я «сброслю» переменную « смещение» до ее исходного значения.

Это работает практически так, как я хотел бы, пока не произойдет «сброс». В этот момент анимация является яркой (как бы ожидаемой), но она также, кажется, движется в обратном направлении в течение небольшой части времени, прежде чем возобновить «вперед» движение. Наконец, в начале/конце моей пунктирной линии я получаю дополнительный длинный сегмент на пунктирной линии. Я знаю, что они не могут быть равными по длине (не так ли? как вычислить?), но как я могу сделать 2 более коротких сегмента, а не 1 более длинный сегмент?

Кто-нибудь имеет представление о том, что я могу сделать, чтобы получить гладкий вид «марширующих муравьев»? Какие-либо другие идеи по хорошему способу (с помощью анимации) вызвать глаз пользователя на определенную область экрана? (Необходимо окружить определенную область, не скрывая ее.)

Текущий код:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextClearRect(context, rect);

    // Rounded corner will be 10% of average side length (i.e., (w + h) / 2)
    float averageSide = ([self HighlightRect].size.width + [self HighlightRect].size.height) / 2.0;
    float roundSize = averageSide * 0.10;

    // offset is a static, class variable
    offset += roundSize / 4.0;
    if ([WhereIAmView offset] < roundSize) {
        offset = roundSize;
    }
    if ([WhereIAmView offset] > ([self HighlightRect].size.width - roundSize)) {
        offset = roundSize;
    }

    // Set the "main" color of the rounded rectangle
    UIColor *lineColor = [UIColor colorWithRed:027.0/255.0 green:050.0/255.0 blue:224.0/255.0 alpha:1.0];
    CGContextSetStrokeColorWithColor(context, [lineColor CGColor]);
    CGContextSetLineWidth(context, 16.0);
    CGFloat pattern[] = {25.0, 5.0};
    CGContextSetLineDash(context, offset, pattern, 2);

    CGRect rRect = [self HighlightRect];
    // The top left corner
    CGPoint topLeft = CGPointMake(rRect.origin.x, rRect.origin.y);
    // The top right corner
    CGPoint topRight = CGPointMake(rRect.origin.x + rRect.size.width, rRect.origin.y);
    // The bottom right corner
    CGPoint bottomRight = CGPointMake(rRect.origin.x + rRect.size.width, rRect.origin.y + rRect.size.height);
    // The bottom left corner
    CGPoint bottomLeft = CGPointMake(rRect.origin.x, rRect.origin.y +     rRect.size.height);

    // The two points across the top of the rounded rectangle (left to right)
    CGPoint point1 = CGPointMake(rRect.origin.x + roundSize, rRect.origin.y);
    CGPoint point2 = CGPointMake(rRect.origin.x + rRect.size.width - roundSize, rRect.origin.y);
    // The two points along the right of the rounded rectangle (top to bottom)
    CGPoint point3 = CGPointMake(rRect.origin.x + rRect.size.width, rRect.origin.y + roundSize);
    CGPoint point4 = CGPointMake(rRect.origin.x + rRect.size.width, rRect.origin.y + rRect.size.height - roundSize);
    // The two points along the bottom of the rounded rectangle (right to left)
    CGPoint point5 = CGPointMake(rRect.origin.x + rRect.size.width - roundSize, rRect.origin.y + rRect.size.height);
    CGPoint point6 = CGPointMake(rRect.origin.x + roundSize, rRect.origin.y + rRect.size.height);
    // The two points along the left of the rounded rectangle (bottom to top)
    CGPoint point7 = CGPointMake(rRect.origin.x, rRect.origin.y + rRect.size.height - roundSize);
    CGPoint point8 = CGPointMake(rRect.origin.x, rRect.origin.y + roundSize);

    // Move to point 1
    CGContextMoveToPoint(context, point1.x, point1.y);
    // Add line to point 2 (this is the straight portion across the top)
    CGContextAddLineToPoint(context, point2.x, point2.y);
    // Add curve to point 3 (this is the rounded portion in top right)
    CGContextAddArcToPoint(context, topRight.x, topRight.y, point3.x, point3.y, roundSize);
    // Add line to point 4 (this is the straight portion across the right)
    CGContextAddLineToPoint(context, point4.x, point4.y);
    // Add curve to point 5 (this is the rounded portion in bottom right)
    CGContextAddArcToPoint(context, bottomRight.x, bottomRight.y, point5.x, point5.y, roundSize);
    // Add line to point 6 (this is the straight portion across the bottom)
    CGContextAddLineToPoint(context, point6.x, point6.y);
    // Add curve to point 7 (this is the rounded portion in bottom left)
    CGContextAddArcToPoint(context, bottomLeft.x, bottomLeft.y, point7.x, point7.y, roundSize);
    // Add line to point 8 (this is the straight portion across the left)
    CGContextAddLineToPoint(context, point8.x, point8.y);
    // Add curve to point 1 (this is the rounded portion in top left)
    CGContextAddArcToPoint(context, topLeft.x, topLeft.y, point1.x, point1.y, roundSize);

    // Stroke the path
    CGContextStrokePath(context);

}

bump bump bump

-121--1162661- XSLT Добавить цель = «_ blank» на URL-адрес Я создал XSLT-файл, который выполняется через перечислять SharePoint для создания таблицы ресурсов. Одна его часть создает ссылку, которая выходит за пределы сайта. Я хочу открыть его в новом окне, используя...

Создан XSLT-файл, который выполняется через перечислять SharePoint для создания таблицы ресурсов. Одна его часть создает ссылку, которая выходит за пределы сайта. Я хочу открыть его в новом окне, используя target = «_ blank», но я не уверен, как это сделать в XSLT.

Вот часть, которая создает ссылку:

<xsl:element name="a">
    <xsl:attribute name="href">
        <xsl:value-of select="Website"/>
    </xsl:attribute>
    <xsl:text>Visit Website</xsl:text>
</xsl:element>

Может ли кто-нибудь пролить свет на это для меня? Я довольно новичок в работе с XSLT.

5
задан snowBlind 30 September 2011 в 17:29
поделиться