Make it Vanish Button please.

Discussion in 'iOS Programming' started by IDMah, Dec 20, 2011.

  1. IDMah macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #1
    Me again..

    What is the best approach to make a "button with a label" shrink and Fade out?

    is it better to copy the image with the label and with:
    CGImageCreateWithImageInRect then animate the copy away.

    or

    Can resize and change the alpha on the actual button?

    also if you are interested in animation see my post on
    Flipping Animated Question could use help there too.. ugh..

    thanks
    Ian
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Shrink and fade out.
    UIView animation block ->
    Shrink -> you can set it's transformscale on it's .layer (have to have QuartzCore imported.
    and then fade out, you have an alpha.

    Or describe it a better ;)
     
  3. IDMah thread starter macrumors 6502

    IDMah

    Joined:
    May 13, 2011
    #3
    Yes - Fade in this case is opacity since the background is black.
    But loosely correct better to say cross dissolve in video terms.

    I ended up using Core Animation. Did all I wanted with very little overhead.

    here is what I did for those interested.

    Code:
    CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
    	scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    	scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.3, 0.3, 1.0)];
    	scaleAnim.removedOnCompletion = YES;
    	
    	CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
    	opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
    	opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
    	opacityAnim.removedOnCompletion = YES;
    	
    
           // allow Animation to be put together 'Ganged up' //
    	CAAnimationGroup *animGroup = [CAAnimationGroup animation];
    	animGroup.animations = [NSArray arrayWithObjects:opacityAnim,scaleAnim,  nil];
    	animGroup.duration = 0.4;
    
    	// All my buttons stored in this array //
    	[[[buttonArray objectAtIndex:buttonNumber] layer] addAnimation:animGroup forKey:nil];
    
          // Delay thread from returning before animation is done, couldn't think    
          // of any thing smarter / easier ... //
     [self performSelector:@selector(doNothing) withObject:nil afterDelay:2.0];
       
    
    funny thing was that the delay code didn't seem to work with: CAKeyframeAnimation.

    Also the
    Code:
    animGroup.duration = -0.4; 
    did weird stuff.. stuttery..results

    Anyone know why to both?

    thanks
    Hope this helps someone ... really appreciate this forum.
    It has Helped me heaps.
    thanks again!!!
    Ian
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    I think you are in over your head
    Try using
    Code:
    [UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>
    Basically you do something like this:
    Code:
    - (void)cloudAnimations {
        [self scrollInCloud:cloudLeftImage withDuration:1.5 andWait:0 andRect:CGRectMake(-68, 197, 248, 383)];
        [self scrollInCloud:cloudRightBottomImage withDuration:1.5 andWait:0 andRect:CGRectMake(795, 529, 229, 220)];
        [self scrollInCloud:cloudRightTopImage withDuration:1.5 andWait:0 andRect:CGRectMake(859, 0, 165, 98)];
    }
    
    - (void)scrollInCloud:(UIView *)viewToScroll withDuration:(NSTimeInterval)duration andWait:(NSTimeInterval)wait andRect:(CGRect)rect {
        viewToScroll.alpha = 0.5;
        [UIView animateWithDuration:CLOUD_ANIMATION_DURATION animations:^{
            viewToScroll.alpha = 1;
            viewToScroll.frame = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
    	}];
    }
    
    THis is just a stupid example i jotted down.
    (CLOUD_ANIMATION_DURATION is an #define.
    You can instead of doing viewToScroll.alpha = 1;
    just to viewToScroll.layer.scale (or something similar).
    and if you research, you know there is a complete BOOL, where you can trigger other UIView related stuff ;)

    DO NOTE, if you type in, completed bool -> addSubview.
    The addSubview (or something similar) will be triggered instant.
    Objective-C (if i'm correct, i'm doing a small guess mixed with what I read), will take the block of code, and check if it's scriptable, everything that is scriptable over time, it will do. but anything like adding the subview, it won't actually do "over a certain time", so it will trigger those instantly ;)

    Hope i'm making a bit of sence. but give it a go.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Why do you think a negative duration makes sense?
     

Share This Page