2016-11-15 15 views
0

ユーザーがビューをクリックしたときにバーストアニメーションを実行しようとしています。ユーザが特定のビューをクリックしたときにビューを円形の部分に破裂させます。だから私は、次のように UIView Icon Animation

- (UIImage *) imageWithView:(UIView *)view 
    { 
     UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0); 
     [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

     UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 

     UIGraphicsEndImageContext(); 

     return img; 
    } 

は、その後、私は作品にuiimageが壊れている、次のようにUIViewのはuiimageする

-(void)splitImage:(UIImage *)image 
{ 
    CGFloat imgWidth = image.size.width/2; 
    CGFloat imgheight = image.size.height; 
    CGRect leftImgFrame = CGRectMake(0, 0, imgWidth, imgheight); 
    CGRect rightImgFrame = CGRectMake(imgWidth, 0, imgWidth, imgheight); 

    CGImageRef left = CGImageCreateWithImageInRect(image.CGImage, leftImgFrame); 
    CGImageRef right = CGImageCreateWithImageInRect(image.CGImage, rightImgFrame); 

    UIImage* leftImage = [UIImage imageWithCGImage:left]; 
    UIImage* rightImage = [UIImage imageWithCGImage:right]; 

    CGImageRelease(left); 
    CGImageRelease(right); 
} 

を変換している。しかし、それをしている間直面イム特定の問題があります。

  1. 私はuiimageを2個に分割することはできますが、 個の動的部分に分割することはできません。
  2. どのように私は、uiviewがこれらの壊れたuiimagesで円形の部分に爆発しているように見えるのですか?

UPDATE:

-(void)startAnimation{ 


    //Add the initial circle 
// UIView* circleView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 60, 60)]; 
    UIView *circleView = [[UIImageView alloc] initWithFrame:self.submit.bounds]; 

    circleView.bounds = self.submit.bounds; 

    CAShapeLayer *circleLayer = [CAShapeLayer layer]; 

    //set colors 
    [circleLayer setStrokeColor:[[UIColor redColor] CGColor]]; 
    [circleLayer setFillColor:[[UIColor clearColor] CGColor]]; 
    [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:circleView.bounds] CGPath]]; 
    [circleView.layer addSublayer:circleLayer]; 
    [self.view addSubview:circleView]; 

    //Animate circle 
    [circleView setTransform:CGAffineTransformMakeScale(0, 0)]; 
    [UIView animateWithDuration:0.7 animations:^{ 
     [circleView setTransform:CGAffineTransformMakeScale(1.3, 1.3)]; 
    } completion:^(BOOL finished) { 
     circleView.hidden = YES; 
     //start next animation 
     [self createIconAnimation]; 
    }]; 
} 

-(void)createIconAnimation{ 

    //load icon which pops up 
    UIImageView* iconImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_tick"]]; 
    iconImage.frame = CGRectMake(50, 50, 60, 60); 
    iconImage.bounds = self.submit.bounds; 
    [iconImage setTransform:CGAffineTransformMakeScale(0, 0)]; 
    [self.view addSubview:iconImage]; 

    //animate icon 
    [UIView animateWithDuration:0.3/1.5 animations:^{ 
     iconImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1); 
    } completion:^(BOOL finished) { 
     [UIView animateWithDuration:0.3/2 animations:^{ 
      iconImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9); 
     } completion:^(BOOL finished) { 
      [UIView animateWithDuration:0.3/2 animations:^{ 
       iconImage.transform = CGAffineTransformIdentity; 
      }]; 
     }]; 
    }]; 


    //add circles around the icon 
    int numberOfCircles = 20; 
    CGPoint center = iconImage.center; 
    float radius= 35; 
    BOOL isBig = YES;; 
    for (int i = 0; i<numberOfCircles; i++) { 

     float x = radius*cos(M_PI/numberOfCircles*i*2) + center.x; 
     float y = radius*sin(M_PI/numberOfCircles*i*2) + center.y; 

     float circleRadius = 10; 
     if (isBig) { 
      circleRadius = 5; 
      isBig = NO; 
     }else{ 
      isBig = YES; 
     } 

     UIView* circleView = [[UIView alloc] initWithFrame:CGRectMake(x, y, circleRadius, circleRadius)]; 
     CAShapeLayer *circleLayer = [CAShapeLayer layer]; 
     [circleLayer setStrokeColor:[[UIColor redColor] CGColor]]; 
     [circleLayer setFillColor:[[UIColor redColor] CGColor]]; 
     [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:circleView.bounds] CGPath]]; 
     [circleView.layer addSublayer:circleLayer]; 
     [self.view addSubview:circleView]; 

     //animate circles 
     [UIView animateWithDuration:0.8 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
      [circleView setTransform:CGAffineTransformMakeTranslation(radius/3*cos(M_PI/numberOfCircles*i*2), radius/3*sin(M_PI/numberOfCircles*i*2))]; 
      [circleView setTransform:CGAffineTransformScale(circleView.transform, 0.01, 0.01)]; 
     } completion:^(BOOL finished) { 
      circleView.hidden = YES; 
     }]; 


    } 

} 

アニメーションはself.submitボタンの上にある必要がありますが、それはそれの上に配置されていません...私の更新されたコードを以下に示し

+0

どのように見えるかの例を挙げることができますか?あなたが探している作業は、派手な爆発などが必要な場合は、おそらく3D機能が必要なので、達成するのは簡単ではありません。私はかつてこれをボロノイパターンで試みました。それは非常によく働いたが、3D効果は – ben

+0

https://raw.githubusercontent.com/ChadCSong/ShineButton/master/demo_shine_others.gif –

+0

イムでした。最初に円が大きくなると円が消え、アイコンの周りに円が表示されます。私に30分を与えてください。私は答えとして投稿します –

答えて

1

ここでは、このコードをView Controllerに追加するだけです。

http://imgur.com/a/PhcIv

ちょうどあなたの望ましい結果を得るために、色やアニメーションで遊ん:それはあなたにこの結果を与えます。

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    [self startAnimation]; 

} 

-(void)startAnimation{ 

    //Add the initial circle 
    UIView* circleView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 60, 60)]; 
    CAShapeLayer *circleLayer = [CAShapeLayer layer]; 

    //set colors 
    [circleLayer setStrokeColor:[[UIColor redColor] CGColor]]; 
    [circleLayer setFillColor:[[UIColor clearColor] CGColor]]; 
    [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:circleView.bounds] CGPath]]; 
    [circleView.layer addSublayer:circleLayer]; 
    [self.view addSubview:circleView]; 

    //Animate circle 
    [circleView setTransform:CGAffineTransformMakeScale(0, 0)]; 
    [UIView animateWithDuration:0.7 animations:^{ 
     [circleView setTransform:CGAffineTransformMakeScale(1.3, 1.3)]; 
    } completion:^(BOOL finished) { 
     circleView.hidden = YES; 
     //start next animation 
     [self createIconAnimation]; 
    }]; 
} 

-(void)createIconAnimation{ 

    //load icon which pops up 
    UIImageView* iconImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Untitled"]]; 
    iconImage.frame = CGRectMake(50, 50, 60, 60); 
    [iconImage setTransform:CGAffineTransformMakeScale(0, 0)]; 
    [self.view addSubview:iconImage]; 

    //animate icon 
    [UIView animateWithDuration:0.3/1.5 animations:^{ 
     iconImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1); 
    } completion:^(BOOL finished) { 
     [UIView animateWithDuration:0.3/2 animations:^{ 
      iconImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9); 
     } completion:^(BOOL finished) { 
      [UIView animateWithDuration:0.3/2 animations:^{ 
       iconImage.transform = CGAffineTransformIdentity; 
      }]; 
     }]; 
    }]; 


    //add circles around the icon 
    int numberOfCircles = 20; 
    CGPoint center = iconImage.center; 
    float radius= 35; 
    BOOL isBig = YES;; 
    for (int i = 0; i<numberOfCircles; i++) { 

     float x = radius*cos(M_PI/numberOfCircles*i*2) + center.x; 
     float y = radius*sin(M_PI/numberOfCircles*i*2) + center.y; 

     float circleRadius = 10; 
     if (isBig) { 
      circleRadius = 5; 
      isBig = NO; 
     }else{ 
      isBig = YES; 
     } 

     UIView* circleView = [[UIView alloc] initWithFrame:CGRectMake(x, y, circleRadius, circleRadius)]; 
     CAShapeLayer *circleLayer = [CAShapeLayer layer]; 
     [circleLayer setStrokeColor:[[UIColor redColor] CGColor]]; 
     [circleLayer setFillColor:[[UIColor redColor] CGColor]]; 
     [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:circleView.bounds] CGPath]]; 
     [circleView.layer addSublayer:circleLayer]; 
     [self.view addSubview:circleView]; 

     //animate circles 
     [UIView animateWithDuration:0.8 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
      [circleView setTransform:CGAffineTransformMakeTranslation(radius/3*cos(M_PI/numberOfCircles*i*2), radius/3*sin(M_PI/numberOfCircles*i*2))]; 
      [circleView setTransform:CGAffineTransformScale(circleView.transform, 0.01, 0.01)]; 
     } completion:^(BOOL finished) { 
      circleView.hidden = YES; 
     }]; 


    } 

} 



@end 
+0

ありがとう作品bro..itありがとう私は任意の合併症に直面 –

+0

あなたは私にソースコードを教えてくださいできますか?あなたは円が表示されていないので、 –

+0

私はuiview –