How to unhide view with animations

后端 未结 4 697
孤街浪徒
孤街浪徒 2021-02-19 03:47

Say I have a hidden view in Xcode for iOS. Now, when I set the view to not hidden (view.hidden=NO), how can I make it so that it now appears, but with animations?

相关标签:
4条回答
  • 2021-02-19 03:48
    -(void)showView{
    
      [UIView beginAnimations: @"Fade Out" context:nil];
      [UIView setAnimationDelay:0];
      [UIView setAnimationDuration:.5];
      //show your view with Fade animation lets say myView
      [myView setHidden:FALSE];
      [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(hideView) userInfo:nil repeats:YES];
    
      [UIView commitAnimations];
    }
    
    
    -(void)hideView{
      [UIView beginAnimations: @"Fade In" context:nil];
      [UIView setAnimationDelay:0];
      [UIView setAnimationDuration:.5];
      //hide your view with Fad animation
      [myView setHidden:TRUE];
      [UIView commitAnimations];
    }
    

    OR you can try this way

    self.yourView.alpha = 0.0;
    [UIView beginAnimations:@"Fade-in" context:NULL];
    [UIView setAnimationDuration:1.0];
    self.yourView.alpha = 1.0;
    [UIView commitAnimations];
    
    0 讨论(0)
  • 2021-02-19 03:51

    If you want other animations than only fading then use this method

    [UIView transitionWithView:_yourView duration:1.0 options:UIViewAnimationOptionTransitionCurlDown animations:^(void){
    
                [_yourView setHidden:NO];
    
            } completion:nil];
    
    0 讨论(0)
  • 2021-02-19 03:57

    For a fade, you can adjust the alpha property of the view.

    myView.alpha = 0;
    [UIView animateWithDuration:0.5 animations:^{
        myView.alpha = 1;
    }];
    

    That will apply a fade in over 0.5 seconds to the view myView. Many UIView properties are animatable; you aren't just limited to alpha fades. You can change background colours, or even rotate and scale a view, with animation. If you need further control and advanced animation, you can then move into Core Animation - a much more complex animation framework.

    0 讨论(0)
  • 2021-02-19 04:15

    What you probably want is not to set view.hidden, but to set view.alpha to 0 (corresponds to hidden = YES) or 1 (hidden = NO).

    You can then use implicit animations to show the view, e.g

    [UIView animateWithDuration:0.3 animations:^() {
        view.alpha = 1.0;
    }];
    
    0 讨论(0)
提交回复
热议问题