How to unhide view with animations

后端 未结 4 711
孤街浪徒
孤街浪徒 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];
    

提交回复
热议问题