게임: 쉬지 않고 돌려보았다

18219 단어 iOS

이것저것 빠르게 날아오르는데 소스 코드밖에 없어요.
View.m
- (void)drawRect:(CGRect)rect
{

    //// General Declarations
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = UIGraphicsGetCurrentContext();

    //// Color Declarations
    UIColor* color3 = [UIColor colorWithRed: 1 green: 0.41 blue: 0.114 alpha: 1];

    //// Gradient Declarations
    NSArray* gradientColors = [NSArray arrayWithObjects:
                               (id)color3.CGColor,
                               (id)[UIColor colorWithRed: 1 green: 0.705 blue: 0.557 alpha: 1].CGColor,
                               (id)[UIColor whiteColor].CGColor, nil];
    CGFloat gradientLocations[] = {0, 0.61, 1};
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)gradientColors, gradientLocations);

    //// Bezier Drawing
    UIBezierPath* bezierPath = [UIBezierPath bezierPath];
    [bezierPath moveToPoint: CGPointMake(24.7, 24.7)];
    [bezierPath addCurveToPoint: CGPointMake(24.7, 35.3) controlPoint1: CGPointMake(21.77, 27.63) controlPoint2: CGPointMake(21.77, 32.37)];
    [bezierPath addCurveToPoint: CGPointMake(35.3, 35.3) controlPoint1: CGPointMake(27.63, 38.23) controlPoint2: CGPointMake(32.37, 38.23)];
    [bezierPath addCurveToPoint: CGPointMake(35.3, 24.7) controlPoint1: CGPointMake(38.23, 32.37) controlPoint2: CGPointMake(38.23, 27.63)];
    [bezierPath addCurveToPoint: CGPointMake(24.7, 24.7) controlPoint1: CGPointMake(32.37, 21.77) controlPoint2: CGPointMake(27.63, 21.77)];
    [bezierPath closePath];
    [bezierPath moveToPoint: CGPointMake(50, 30)];
    [bezierPath addCurveToPoint: CGPointMake(30, 50) controlPoint1: CGPointMake(50, 41.05) controlPoint2: CGPointMake(41.05, 50)];
    [bezierPath addCurveToPoint: CGPointMake(10, 30) controlPoint1: CGPointMake(18.95, 50) controlPoint2: CGPointMake(10, 41.05)];
    [bezierPath addCurveToPoint: CGPointMake(30, 0) controlPoint1: CGPointMake(10, 18.95) controlPoint2: CGPointMake(27.19, 0)];
    [bezierPath addCurveToPoint: CGPointMake(50, 30) controlPoint1: CGPointMake(32.81, 0) controlPoint2: CGPointMake(50, 18.95)];
    [bezierPath closePath];
    CGAffineTransform trans = CGAffineTransformMakeScale(self.bounds.size.width/60,
                                                         self.bounds.size.height/60);
    [bezierPath applyTransform:trans];
    CGContextSaveGState(context);
    [bezierPath addClip];
    CGContextDrawLinearGradient(context, gradient,
                                CGPointMake(self.bounds.size.width/2, 0),
                                CGPointMake(self.bounds.size.width/2, self.bounds.size.height),
                                0);
    CGContextRestoreGState(context);
    [[UIColor orangeColor] setStroke];

    bezierPath.lineWidth = 1;
    [bezierPath stroke];


    //// Cleanup
    CGGradientRelease(gradient);
    CGColorSpaceRelease(colorSpace);


}

ViewController.m
-(void)viewDidAppear:(BOOL)animated
{
    // y軸に対して回転.(z軸を指定するとUIViewのアニメーションのように回転)
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    // アニメーションのオプションを設定
    animation.duration = 5; // アニメーション速度
    animation.repeatCount = HUGE_VALF; // 繰り返し回数

    // 回転角度を設定
    animation.fromValue = [NSNumber numberWithFloat:0.0]; // 開始時の角度
    animation.toValue = [NSNumber numberWithFloat:2 * M_PI]; // 終了時の角度

    // アニメーションを追加
    [self.arrowView.layer addAnimation:animation forKey:@"rotate-layer"];
}

좋은 웹페이지 즐겨찾기