2010-06-24 413 views
1

基本上這是我的代碼,它繪製了一個有4個不同顏色和相等大小的象限的圓。我想要做的是將這個圓順時針和逆時針旋轉,即順時針旋轉,當我觸摸圓並沿順時針方向拖動它,反之亦然。 我已經通過核心圖形做出了圓圈。還有一件事是圓圈必須以高速旋轉,並逐漸減速直到停止。在這方面的任何幫助將不勝感激。 請儘快回覆。如何順時針和逆時針旋轉圓圈?

- (void)drawRect:(CGRect)rect { 

    CGContextRef context = UIGraphicsGetCurrentContext(); 
// CGRect mainSquare = self.bounds/2; 

    CGRect 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); 

} 
+0

嗯,至少你在「回覆儘快」之前說「請」,所以沒有粗魯的行爲從我這裏投降。 ;) – John 2010-06-24 22:05:08

+0

嗯,如果它是一個圓圈,你不會注意到一個旋轉的權利? – 2010-06-24 22:05:52

+0

邁克爾,是的,除了裏面的彩色象限。 – John 2010-06-24 22:08:31

回答

0

您可以使用變換&動畫:

[UIView animateWithDuration:0.5 
       animations:^{ 
        self.transform = CGAffineTransformRotate(self.transform, 30); 
       } 
       completion:^(BOOL completed){ 
        NSLog(@"Completed"); 
       }]; 

只記得幀無效後轉換。我認爲你可以設置一些條件來根據年度要求相應地改變持續時間。任何進一步的問題只是在這裏發佈。