【问题标题】:How to rotate a circle clockwise and anticlockwise?如何顺时针和逆时针旋转一个圆圈?
【发布时间】:2010-06-24 21:55:59
【问题描述】:

基本上这是我的代码,它绘制了一个带有 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);

}

【问题讨论】:

  • 好吧,至少你在“尽快回复”之前说“请”,所以我没有粗鲁的反对意见。 ;)
  • 嗯,如果是一个圆圈,你不会注意到旋转吧?
  • 迈克尔,是的,除了里面的彩色象限。
  • @Michael Dorgan 它有彩色片段,所以除非你是多重色盲或在单调显示器上查看它,否则你可能会注意到:P

标签: iphone


【解决方案1】:

您可以使用变换和动画:

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

请记住变换后帧无效。我认为您可以设置一些条件以根据您的要求相应地更改持续时间。有任何问题,请在此处发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多