【问题标题】:Animating image on event事件上的动画图像
【发布时间】:2014-09-04 05:08:00
【问题描述】:

我有一个圆圈内的圆圈大约 10 个圆圈的图像,每个不同的颜色我想在按钮从中心到外部单击时一个一个地显示它们,在另一个按钮上单击从外到内一个一个地消失。这可能吗?如何? 请推荐

【问题讨论】:

    标签: ios animation uiimageview


    【解决方案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
    

    【讨论】:

    • 就在那个帮助函数设置框架代码那里..@akshay
    • 感谢您的帮助,但这不是我想要的。我有一个带有圆圈的图像,每个圆圈都有不同的颜色
    猜你喜欢
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多