开发者

How to rotate a circle(drawn through core graphics) clockwise and anticlockwise?

This is my code.I want to rotate my circle clockwise and anticlockwise.if anyone knows how to do it for a circle drawn with core graphics' please guide me how to do it.

- (void)drawRect:(CGRect)rect { 

    CGContextRef context = UIGraphicsGetCurrentContext();
    mainSquare = CGRectMake(X_SPACE, Y_SPACE, 220, 200);
    CGContextSaveGState(context);

    // Create circle path and clip
    CGContextAddEllipseInRect(context, mainSquare);
    CGContextClip(context);

    // Define rects
    NSLog(@"helll  %f",mainSquare.size.width);
     CGRect topLeft = CGRectMake(mainSquare.origin.x, mainSquare.origin.y, (mainSquare.size.width / 2) , (mainSquare.size.height / 2) );
     CGRect topRight = CGRectMake((mainSquare.size.width / 2) + X_SPACE, mainSquare.origin.y, mainSquare.size.width / 2, (mainSquare.size.height / 2) );
     CGRect bottomLeft = CGRectMake(mainSquare.origin.x, (mainSquare.size.height / 2) + Y_SPACE, mainSquare.size.width / 2, (mainSquare.size.height / 2) );
     CGRect bottomRight = CGRectMake((mainSquare.size.width / 2) + X_SPACE, (mainSquare.size.height / 2) + Y_SPACE, mainSquare.size.width / 2, mainSquare.size.height / 2);  

    // Define colors
    CGColorRef topLeftColor = [[UIColor redColor] CGColor];
    CGColorRef topRightColor = [[UIColor blueColor] CGColor];
    CGColorRef bottomLeftColor = [[UIColor greenColor] CGColor];
    CGColorRef bottomRightColor = [[UIColor yellowColor] CGColor];

    // Fill rects with colors
    CGContextSetFillColorWithColor(context, topLeftColor);
    CGContextFillRect(context, topLeft);

    CGContextSetFillColorWithColor(context, topRightColor);
    CGContextFillRect(context, topRight);

    CGContextSetFillColorWithColor(context, bottomLeftColor);
    CGContextFillRect(context, bottomLeft);

    CGContextSetFillColorWithColor(context, bottomRightColor);
    CGContextFillRect(context, bottomRight);


    CGContextRestoreGState(context);

}


 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

     [super touchesBegan:touches withEvent:event];
     UITouch *touch = [[event allTouches] anyObject]; 
     swipeBackward = [touch locationInView: [touch view]]; 
 }

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

     [super touchesEnded:touches withEvent:event]; 
     UITouch *touch = [[event allTouches] anyObject]; 
     swipeForward = [touch locationInView: [touch view]]; 

     double dx = swipeBackward.x - swipeForward.x;
    // double dy = swipeBackward.y - swipeForward.y;     

     if( (swipeBackward.x < 160) && (swipeForward.x < 160) && (swipeBackward.y <= 151) && (swipeForward.y > 151) ) 
     {  
             NSLog(@"Rotate Anticlockwise");
             mainSquare.transform = CGAffineTransformMakeRotation(63.0*radianConst);

     }  

     else if( (swipeBackward.x < 160) && (swipeForward.x < 160) && (swipeBackward.y >= 151) && (swipeForward.y < 151) )
     {
             NSLog(@"Rotate Clockwise");

     }

     else if( (swipeBackward.x > 160) && (swipeForward.x > 160) && (swipeBackwar开发者_JAVA技巧d.y <= 151) && (swipeForward.y > 151) ) 
     {          
            NSLog(@"Rotate Clockwise"); 

     }  

     else if( (swipeBackward.x > 160) && (swipeForward.x > 160) &&  (swipeBackward.y >= 151) && (swipeForward.y < 151) )
     {
             NSLog(@"Rotate Anticlockwise");             

     }

     else if( (swipeBackward.y > 151) && (swipeForward.y > 151) ) 
     { 
         if (dx > 0 ) 
         {
             NSLog(@"Rotate Clockwise");

         }  

         else 
         {
             NSLog(@"Rotate Anticlockwise");


         }

     }
     else
     { 
         if (dx > 0 ) 
         {
             NSLog(@"Rotate Anticlockwise");


         }  

         else 
         {
             NSLog(@"Rotate Clockwise");


         }

     }


}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜