Simple Animation Hiding And Showing UI Elements iOS Programmatically

Hiding and showing UI Elements (or views) in iOS programmatically is pretty easy. It is not custom though. This is the simplest way I can animate views. You can do this by making your views (With images) rasterized. What is the meaning of rasterized? As far as I can remember, the IDE or compiler Xcode will make your image low quality to better the animation.

What I did was I rasterized the image and then return it to its high quality version by turning off the shouldRasterized property. Here, take a look at my source codes.

SHOWING UI ELEMENTS

- (void)showTopElements

{

    self.photoButton.layer.shouldRasterize = YES;

    self.videoButton.layer.shouldRasterize = YES;

    self.photoButton.layer.shouldRasterize = YES;

    self.videoButton.layer.shouldRasterize = YES;

    

    [UIView transitionWithView:self.photoButton

                      duration:0.5

                       options:UIViewAnimationOptionTransitionCrossDissolve

                    animations:NULL

                    completion:NULL];

    

    [UIView transitionWithView:self.videoButton

                      duration:0.5

                       options:UIViewAnimationOptionTransitionCrossDissolve

                    animations:NULL

                    completion:NULL];

    

    [UIView transitionWithView:self.searchButton

                      duration:0.5

                       options:UIViewAnimationOptionTransitionCrossDissolve

                    animations:NULL

                    completion:NULL];

    

    [UIView transitionWithView:self.coverView

                      duration:0.5

                       options:UIViewAnimationOptionTransitionCrossDissolve

                    animations:NULL

                    completion:NULL];

    

    

    //    self.photoButton.hidden = YES;

    self.videoButton.hidden = NO;

    self.searchButton.hidden = NO;

    self.coverView.hidden = NO;

    

    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];

    [self setNeedsStatusBarAppearanceUpdate];

}



HIDING UI ELEMENTS
- (void)hideTopElements
{
    self.photoButton.layer.shouldRasterize = YES;
    self.videoButton.layer.shouldRasterize = YES;
    self.photoButton.layer.shouldRasterize = YES;
    self.videoButton.layer.shouldRasterize = YES;

    [UIView transitionWithView:self.photoButton
                      duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:NULL
                    completion:NULL];
    
    [UIView transitionWithView:self.videoButton
                      duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:NULL
                    completion:NULL];
    
    [UIView transitionWithView:self.searchButton
                      duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:NULL
                    completion:NULL];
    
    [UIView transitionWithView:self.coverView
                      duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:NULL
                    completion:NULL];
    
    
//    self.photoButton.hidden = YES;
    self.videoButton.hidden = YES;
    self.searchButton.hidden = YES;
    self.coverView.hidden = YES;
    
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
    [self setNeedsStatusBarAppearanceUpdate];
    
   }

If you can't understand the codes here or need some help, comment here and email me.

Post a Comment