2014-09-04 51 views
-3

我有一個圓圈內的圖像大約10個圓圈,每個不同的顏色我想要一個一個的顯示他們按鈕從中心到外部點擊並在另一個按鈕上點擊從外部逐個消失內。這是可能的和如何? 請建議關於事件的動畫圖像

回答

1

您可以從下面的代碼獲得幫助我不是錯了,你正在尋找的雷達風格動畫

#import "RadarAnimation.h" 

@implementation RadarAnimation 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 

     [self SetUPAnimation]; 

     // Initialization code 
    } 
    return self; 
} 


-(void)SetUPAnimation 
{ 


    [self AddRader]; 
    double delayInSeconds = 1.5; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     [self AddRader]; 
    }); 


} 

-(void)AddRader 
{ 
    UIView *view = [[UIView alloc] init]; 
    // view.backgroundColor = [UIColor blueColor]; 
    view.frame=self.frame; 
    [self setWidth:[Helper currentWidth] ofView:view]; 
    [self setHeight:[Helper currentWidth] ofView:view]; 
    [self setXPossitionto:self.frame.size.width/2-view.frame.size.width/2 ofView:view]; 
    [self setYPossitionto:self.frame.size.height/2-view.frame.size.height/2 ofView:view]; 


    view.layer.cornerRadius = CGRectGetHeight(view.frame)/2; 
    view.tag=175751; 
    int kRingExpansionTime=6.0; 

    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
    scaleAnimation.duration = kRingExpansionTime; 
    scaleAnimation.repeatCount = HUGE_VAL; 
    scaleAnimation.autoreverses = YES; 
    scaleAnimation.fromValue = [NSNumber numberWithFloat:0.0]; 
    scaleAnimation.toValue = [NSNumber numberWithFloat:1.8]; 

    [view.layer addAnimation:scaleAnimation forKey:@"scale"]; 


    // fade out the ring part way thru the animation 
    CABasicAnimation* alphaAnim = [CABasicAnimation animationWithKeyPath:@"opacity"]; 
    alphaAnim.fromValue = [NSNumber numberWithFloat:0.3]; 
    alphaAnim.toValue  = [NSNumber numberWithFloat:0.1]; 
    alphaAnim.beginTime = kRingExpansionTime * 0.7f;  // start part way thru 
    alphaAnim.duration = kRingExpansionTime - alphaAnim.beginTime; 

    CAAnimationGroup* group = [CAAnimationGroup animation]; 
    group.duration = kRingExpansionTime; 
    group.repeatCount = HUGE_VALF;  // repeat forever 
    group.animations = [NSArray arrayWithObjects:scaleAnimation,alphaAnim, nil]; 

    [view.layer addAnimation:group forKey:nil]; 

    view.backgroundColor = [UIColor colorWithRed:0/255.0 green:135.0/255.0 blue:219.0/255.0 alpha:0.5]; 
    view.alpha=0.4; 
    view.layer.borderColor = [UIColor colorWithRed:0/255.0 green:135.0/255.0 blue:255.0/255.0 alpha:1.0].CGColor; 
    view.layer.borderWidth = 2.0; 
    //view.center=_VwEmptyplaceholder.center; 
    //view.center=CGPointMake(_VwEmptyplaceholder.frame.size.width/2, _VwEmptyplaceholder.frame.size.height/2); 
    view.userInteractionEnabled=NO; 
    view.tag=175751; 

    //[self insertSubview:view belowSubview:btn]; 
} 
-(void)setXPossitionto:(CGFloat)xpostion ofView:(UIView *)view 
{ 
    CGRect frame = view.frame; 
    frame.origin.x = xpostion; 
    view.frame=frame; 
} 

-(void)setYPossitionto:(CGFloat)ypostion ofView:(UIView *)view 
{ 
    CGRect frame = view.frame; 
    frame.origin.y = ypostion; 
    view.frame=frame; 
} 

-(void)setWidth:(CGFloat)Width ofView:(UIView *)view 
{ 
    CGRect frame = view.frame; 
    frame.size.width = Width; 
    view.frame=frame; 
} 

-(void)setHeight:(CGFloat)Height ofView:(UIView *)view 
{ 
    CGRect frame = view.frame; 
    frame.size.height = Height; 
    view.frame=frame; 
} 
/* 
// Only override drawRect: if you perform custom drawing. 
// An empty implementation adversely affects performance during animation. 
- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
} 
*/ 

@end 
+0

什麼** **助手在這個代碼? @Parth – 2014-09-04 06:04:15

+0

只是在幫助函數seting框架代碼是有.. .. @akshay – 2014-09-04 09:05:46

+0

感謝您的幫助,但這不是我想要的。我有一個圓圈內的圖像,每個不同的顏色,我想要顯示他們一個按鈕點擊從中心到外部和另一個按鈕點擊消失從外部到內部一個接一個@parth – 2014-09-04 09:46:43