How can I make the line turn?

zmbdr

I drew the line that turn like clock.

This is the line's moving of my ideal

this is the line's moving of my ideal

but my code moves like this

but my code works like this

How can I make a line like the second picture's line?

Here is my code

LineLayer.m

    - (void)drawInContext:(CGContextRef)ctx
    {
        CGMutablePathRef path = CGPathCreateMutable();
        CGPoint points[] = {
            CGPointMake(160, 220),
            CGPointMake(160, 120),
        };

        int numPoints = sizeof(points)/sizeof(points[0]);
        CGPathAddLines(path, NULL, points, numPoints);

        CGContextAddPath(ctx, path);
        CGPathRelease(path);

        UIColor *lineColor = [UIColor colorWithWhite:1.0 alpha:1.0];
        CGContextSetStrokeColorWithColor(ctx, lineColor.CGColor);
        CGContextSetLineWidth(ctx, 5.0);
        CGContextDrawPath(ctx, kCGPathStroke);    
}

ViewController.h

- (void)setup
{    
    LineLayer *linelayer = [LineLayer layer];
    linelayer.frame = CGRectInset(self.view.bounds,0.0,0.0);
    linelayer.anchorPoint = CGPointMake(0.5, 0.5);

    [self.view.layer addSublayer:linelayer];
    [linelayer setNeedsDisplay];

 CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.toValue = [NSNumber numberWithFloat:M_PI / 2.0];
    animation.duration = 0.5;          
    animation.repeatCount = MAXFLOAT;   
    animation.cumulative = YES;         
    [linelayer addAnimation:animation forKey:@"ImageViewRotation"];
}
Shebin Koshy

you need a clock seconds needle or something like that??

#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)

NSTimer *timer1;//global declaration
CALayer *layerLine;//global declaration

in viewDidLoad()

layerLine = [CALayer layer];
[layerLine setFrame:CGRectMake(0, 0,2, 90)];
[layerLine setBackgroundColor:[UIColor yellowColor].CGColor];
[self.view.layer addSublayer:layerLine];
CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, ([[UIScreen mainScreen] bounds].size.height/2)-(layerLine.frame.size.height/4));
layerLine.anchorPoint = CGPointMake(0, 0);
layerLine.position = centerPoint;
layerLine.transform = CATransform3DMakeRotation(M_PI_2*2, 0.0, 0.0, 1.0);
if (!timer)
{
  timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(onTickTick) userInfo:nil repeats:YES];
}

timer invoking method

-(void)onTickTick
{
static int i = 180;
if (i==540)//if u change the value for i, it may affect this condition
{
    i=180;
}
i=i+6;//u can replace 6 with 30 or any other value as u require
layerLine.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(i), 0.0, 0.0, 1);
}

Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.

En caso de infracción, por favor [email protected] Eliminar

Editado en
0

Déjame decir algunas palabras

0Comentarios
Iniciar sesiónRevisión de participación posterior

Artículos relacionados

How can I turn a list of lists into a string with a new line for each list and no commas

How can I make a string jump to a new line after a certain number of characters in PDFsharp?

How can I make this dropdown menu appear on the same line as its parent?

How can I make two joined open arcs(without the horizontal line) in HTML canvas?

How can I turn coordinates to two dimensional array in javascript

How can I turn off includeSubDomains for HSTS in rails?

How can I turn a csv file into a list of list in python

Python: How can I turn every negative number into a zero?

How can I turn a string that contains numbers and operators into a result?

How can I take a list input from a file and turn it into a dictionary?

How can I turn this list of strings into a dataframe in pandas

How can I suppress (not print) line numbers?

How can I fit a nonlinear line in R?

How can I make a subquery with EXISTS on Knex?

How can I make angled table headers?

How can i make this factorial function recursive?

How can I make the `PlaceAutocompleteFragment` resolved?

How can I make a clickable link in an NSAttributedString?

How can I make a reusable function?

How can i make radio button unselect

How can I make the string in function work?

How can I make a column vector?

How can I make a background in SwiftUI translucent?

How can I make a condition for a variable?

How can I make a countdown with NSTimer?

How can I make $http with authentication?

How can I make Flexbox Item a hyperlink?

How can I make this tab active by default?

How can I make subfolders of subfolders?

TOP Lista

CalienteEtiquetas

Archivo